English 中文(简体)
您如何在 Matplotlib 或 Mayavi 中代表以下的 3D 数据?
原标题:How would you represent the following 3D data in Matplotlib or Mayavi?

我有一大套我试图在 3D 中显示的数据, 希望找到一个模式。 我花了相当长的时间读、研究和编码, 但后来我意识到我的主要问题不是编程,

Matplotlib s mplot3d 提供了许多选项( 网络框架、 轮廓、 填满的轮廓等 ), 玛雅维(Maya Vi) 也是如此 。 但有很多选择( 以及每个选择都有自己的学习曲线 ), 我几乎迷失了方向, 不知道从哪里开始 。 所以, 我的问题是, 如果必须处理这些数据, 你会使用什么样的计划方法?

我的数据基于日期。 对于每个时间点, 我都会绘制一个值( 列表实际 ) 。

但对于每个时间点,我也有上限、下限和中点。 这些限值和中点基于种子,在不同平面上。

我想辨别点点或确定模式, 在我的实际阅读中何时或之前发生重大改变 。 是所有飞机的上限达到时? 还是相互接近? 实际值达到上限/ 中/ 下限时? 是上/ 中/ 下限时吗? 当一架飞机的上限达到另一架飞机的下限时是上/ 中/ 下限时吗?

在代号I m 粘贴中, 我将数据集简化为几个元素 。 我只是使用简单的散射和线条图, 但是由于数据集的大小( 可能还有 mplot3d 的局限性? ), 我无法使用它来识别我所要寻找的趋势 。

dates = [20110101,20110104,20110105,20110106,20110107,20110108,20110111,20110112]

zAxis0= [       0,       0,       0,       0,       0,       0,       0,       0]
Actual= [    1132,    1184,    1177,     950,    1066,    1098,    1116,    1211]

zAxis1= [       1,       1,       1,       1,       1,       1,       1,       1]
Tops1 = [    1156,    1250,    1156,    1187,    1187,    1187,    1156,    1156]
Mids1 = [    1125,    1187,    1125,    1156,    1156,    1156,    1140,    1140]
Lows1 = [    1093,    1125,    1093,    1125,    1125,    1125,    1125,    1125]

zAxis2= [       2,       2,       2,       2,       2,       2,       2,       2]
Tops2 = [    1125,    1125,    1125,    1125,    1125,    1250,    1062,    1250]
Mids2 = [    1062,    1062,    1062,    1062,    1062,    1125,    1000,    1125]
Lows2 = [    1000,    1000,    1000,    1000,    1000,    1000,     937,    1000]

zAxis3= [       3,       3,       3,       3,       3,       3,       3,       3]
Tops3 = [    1250,    1250,    1250,    1250,    1250,    1250,    1250,    1250]
Mids3 = [    1187,    1187,    1187,    1187,    1187,    1187,    1187,    1187]
Lows3 = [    1125,    1125,    1000,    1125,    1125,    1093,    1093,    1000]

import matplotlib.pyplot
from mpl_toolkits.mplot3d import Axes3D

fig = matplotlib.pyplot.figure()
ax  = fig.add_subplot(111, projection =  3d )

#actual values
ax.scatter(dates, zAxis0, Actual, color =  c , marker =  o )

#Upper limits, Lower limts, and Mid-range for the FIRST plane
ax.plot(dates, zAxis1, Tops1, color =  r )
ax.plot(dates, zAxis1, Mids1, color =  y )
ax.plot(dates, zAxis1, Lows1, color =  b )

#Upper limits, Lower limts, and Mid-range for the SECOND plane
ax.plot(dates, zAxis2, Tops2, color =  r )
ax.plot(dates, zAxis2, Mids2, color =  y )
ax.plot(dates, zAxis2, Lows2, color =  b )

#Upper limits, Lower limts, and Mid-range for the THIRD plane
ax.plot(dates, zAxis3, Tops3, color =  r )
ax.plot(dates, zAxis3, Mids3, color =  y )
ax.plot(dates, zAxis3, Lows3, color =  b )

#These two lines are just dummy data that plots transparent circles that
#occpuy the "wall" behind my actual plots, so that the last plane appears
#floating in 3D rather than being pasted to the plot s background
zAxis4= [       4,       4,       4,       4,       4,       4,       4,       4]
ax.scatter(dates, zAxis4, Actual, color =  w , marker =  o , alpha=0)

matplotlib.pyplot.show()

我得到了这个阴谋,但它只是不 帮助我看到任何关系。

enter image description here I m no mathematician or scientist, so what I really need is help choosing the FORMAT in which to visualize my data. Is there an effective way to show this in mplot3d? Or would you use MayaVis? In either case, which library and class(es) would YOU use?

提前感谢。

问题回答

为了评论你问题(而不是编程)的可视化部分,我模仿了一些例子式的表面图表,以建议您可能想用来探索数据的其他方法。

library("lubridate")
library("ggplot2")
library("reshape2")

dates <- c("2011-01-01","2011-01-04","2011-01-05",
           "2011-01-06","2011-01-07","2011-01-08",
           "2011-01-11","2011-01-12")
dates <- ymd(dates)

Actual<- c(    1132,    1184,    1177,     950,    1066,    1098,    1116,    1211,
               1132,    1184,    1177,     950,    1066,    1098,    1116,    1211,
               1132,    1184,    1177,     950,    1066,    1098,    1116,    1211)
z     <- c(       1,       1,       1,       1,       1,       1,       1,       1,
                  2,       2,       2,       2,       2,       2,       2,       2,
                  3,       3,       3,       3,       3,       3,       3,       3)
Tops <- c(    1156,    1250,    1156,    1187,    1187,    1187,    1156,    1156,
              1125,    1125,    1125,    1125,    1125,    1250,    1062,    1250,
              1250,    1250,    1250,    1250,    1250,    1250,    1250,    1250)
Mids <- c(    1125,    1187,    1125,    1156,    1156,    1156,    1140,    1140,
              1062,    1062,    1062,    1062,    1062,    1125,    1000,    1125,
              1187,    1187,    1187,    1187,    1187,    1187,    1187,    1187)
Lows <- c(    1093,    1125,    1093,    1125,    1125,    1125,    1125,    1125,
              1000,    1000,    1000,    1000,    1000,    1000,     937,    1000,
              1125,    1125,    1000,    1125,    1125,    1093,    1093,    1000)

df <- data.frame( cbind(z, dates, Actual, Tops, Mids, Lows))

dfm <- melt(df, id.vars=c("z", "dates", "Actual"))

在第一个例子中,薄蓝色线是每个z轴所有三个层次的实际值叠加值。

p <- ggplot(data = dfm,
            aes(x = dates,
                y = value,
                group = variable,
                colour = variable)
            ) + geom_line(size = 3) +
                facet_grid(variable ~ z) +
                geom_point(aes(x = dates,
                               y = Actual),
                           colour = "steelblue",
                           size = 3) +
                               geom_line(aes(x = dates,
                                             y = Actual),
                                         colour = "steelblue",
                                         size = 1) +
                                             theme_bw()
p

"https://i.sstatic.net/Fp0xv.png" alt="线性图表"/>

在第二组中,每个面板对每个圆轴的三层(Top、Mid、Low)都有实际值的散射点。

p <- ggplot(data = dfm,
            aes(x = Actual,
                y = value,
                group = variable,
                colour = variable)
            ) + geom_point(size = 3) +
                geom_smooth() +
                facet_grid(variable ~ z) +
                theme_bw()
p

"https://i.sstatic.net/kMgc9.png" alt="correlation"/> https://i.sstatic.net/kMgc9.png" alt="corlation"

谢谢你,Gauden。R其实是我研究的一部分,我已经安装了,但只是没有在辅导课上走得够远。除非它违反了Stackover Flow规则,我很高兴看到你的R代码。

我已经尝试了 2D 表达方式, 但在许多情况下, Tops1/ Tops2/Tops3 的值是相等的( 与 Lows 相同), 所以直线最终会相互重叠, 互相模糊。 这就是为什么我尝试了 3D 选项。 您的3 个 2D 图形面板的想法是一个巨大的建议, 我还没有探讨过 。

我会试一试,但我想3D图能给我一个更清晰的图片, 特别是一个显示价值趋同的线框/网块图, 我可以看到在3D空间的蓝色圆点漂浮在3D空间, 当线框上的线条开始形成一个峰值或干线时。 我只是不能让它工作。

我曾尝试修改""http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutial.html#wireframe-plots" rel=“不跟随 noreferrer">matplotlib s Wireframe 示例 ,但我得到的图案看起来完全不像一个线框。

这是我从下面的代码" https://i.sstatic.net/z9Bjd.png" alt="此处输入图像描述"/>得到的,只有两个数据元素(Tops1和Tops2):

dates = [20110101,20110104,20110105,20110106,20110107,20110108,20110111,20110112]

zAxis0= [       0,       0,       0,       0,       0,       0,       0,       0]
Actual= [    1132,    1184,    1177,     950,    1066,    1098,    1116,    1211]

zAxis1= [       1,       1,       1,       1,       1,       1,       1,       1]
Tops1 = [    1156,    1250,    1156,    1187,    1187,    1187,    1156,    1156]
Mids1 = [    1125,    1187,    1125,    1156,    1156,    1156,    1140,    1140]
Lows1 = [    1093,    1125,    1093,    1125,    1125,    1125,    1125,    1125]

zAxis2= [       2,       2,       2,       2,       2,       2,       2,       2]
Tops2 = [    1125,    1125,    1125,    1125,    1125,    1250,    1062,    1250]
Mids2 = [    1062,    1062,    1062,    1062,    1062,    1125,    1000,    1125]
Lows2 = [    1000,    1000,    1000,    1000,    1000,    1000,     937,    1000]

zAxis3= [       3,       3,       3,       3,       3,       3,       3,       3]
Tops3 = [    1250,    1250,    1250,    1250,    1250,    1250,    1250,    1250]
Mids3 = [    1187,    1187,    1187,    1187,    1187,    1187,    1187,    1187]
Lows3 = [    1125,    1125,    1000,    1125,    1125,    1093,    1093,    1000]

import matplotlib.pyplot
from mpl_toolkits.mplot3d import Axes3D

fig = matplotlib.pyplot.figure()
ax  = fig.add_subplot(111, projection =  3d )

####example code from: http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutorial.html#wireframe-plots
#from mpl_toolkits.mplot3d import axes3d
#import matplotlib.pyplot as plt
#import numpy as np

#fig = plt.figure()
#ax = fig.add_subplot(111, projection= 3d )
#X, Y, Z = axes3d.get_test_data(0.05)
#ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

#plt.show()

X, Y, Z =  dates, Tops1, Tops2 
ax.plot_wireframe(X, Y, Z, rstride=1, cstride=1, color =  g )

matplotlib.pyplot.show()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签