简体   繁体   English

您如何在Matplotlib或Mayavi中表示以下3D数据?

[英]How would you represent the following 3D data in Matplotlib or Mayavi?

I have a large set of data which I'm trying to represent in 3D hoping to spot a pattern. 我有一大堆数据,我试图在3D中表示希望发现一个模式。 I've spent quite some time reading, researching and coding, but then I realized my main problem is NOT the programming, but actually choosing a way to visualize the data . 我花了很长时间阅读,研究和编码,但后来我意识到我的主要问题不是编程,而是实际上选择了一种可视化数据的方法

Matplotlib's mplot3d offers a lot of options (wireframe, contour, filled contour, etc), and so does MayaVi. Matplotlib的mplot3d提供了很多选项(线框,轮廓,填充轮廓等),MayaVi也是如此。 But there are so many choices (and each with its own learning curve) that I'm practically lost and don't know where to start! 但是有很多选择(每个都有自己的学习曲线),我几乎迷失了,不知道从哪里开始! So my question is essentially which plotting method would YOU use if you had to deal with this data? 所以我的问题基本上是你必须处理这些数据时使用哪种绘图方法?

My data is date-based. 我的数据是基于日期的。 For each point in time, I plot a value (the list 'Actual'). 对于每个时间点,我绘制一个值(列表'Actual')。

But for each point in time, I also have an Upper limit, a Lower limit, and a mid-range point. 但是对于每个时间点,我也有一个上限,一个下限和一个中间点。 These limits and midpoints are based on a seed, in different planes. 这些限制和中点基于种子,在不同的平面上。

I want to spot the point or identify the pattern when, or before, a major change happens in my 'Actual' reading. 我希望在我的“实际”读数中发生重大变化时或之前发现该点或识别模式。 Is it when the upper limits on all planes meet? 是在所有飞机的上限都满足时? Or approach one another? 或者彼此接近? Is it when the Actual value touches an Upper/Middle/Lower limit? 当实际值接触上/中/下限时? Is it when Uppers in one plane touch the Lowers of another plane? 是否在一个平面上的Uppers触及另一架飞机的降落时?

In the code I'm pasting, I've reduced the data set to just a few elements. 在我粘贴的代码中,我将数据集简化为几个元素。 I'm just using simple scatter and line plots, but because of the size of the data set (and maybe the limitations of mplot3d?), I'm unable to use it to spot the trends I'm looking for. 我只是使用简单的散点图和线图,但由于数据集的大小(可能是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()

I'm getting this plot, but it just doesn't help me see any co-relationships. 我得到了这个情节,但它并没有帮助我看到任何共同关系。

在此输入图像描述 I'm no mathematician or scientist, so what I really need is help choosing the FORMAT in which to visualize my data. 我不是数学家或科学家,所以我真正需要的是帮助选择FORMAT来可视化我的数据。 Is there an effective way to show this in mplot3d? 有没有一种有效的方法在mplot3d中显示这个? Or would you use MayaVis? 或者你会使用MayaVis吗? In either case, which library and class(es) would YOU use? 在任何一种情况下,您将使用哪个库和类?

Thanks in advance. 提前致谢。

To comment on the visualisation part of your question (not the programming), I have mocked up some example facetted graphs to suggest alternatives you may want to use to explore your data. 为了评论您的问题的可视化部分(而不是编程),我已经模拟了一些示例分面图,以建议您可能想要用来探索数据的替代方案。

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"))

In the first example, the thin blue line is the Actual value superimposed on all three levels in each of the z axes. 在第一个示例中,细蓝线是叠加在每个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

折线图

In the second set, each panel has a scatterplot of the Actual value against the three levels (Top, Mid, Low) in each of the z axes. 在第二组中,每个面板在每个z轴上具有实际值与三个级别(顶部,中间,低)的散点图。

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

相关

Thank you, gauden. 高尔夫,谢谢你。 R was in fact part of my research, and I have installed but just didn't go far enough with the tutorial. R实际上是我研究的一部分,我已经安装了但是对于教程来说还不够。 Unless it's against StackOverFlow rules, I'd appreciate seeing that R code of yours. 除非它违反StackOverFlow规则,否则我会很高兴看到你的R代码。

I have already tried 2D representations, but in many cases the values for Tops1/Tops2/Tops3 (and similarly for Lows) would be equal, so the lines end up overlapping and obscuring one another. 我已经尝试过2D表示,但在很多情况下,Tops1 / Tops2 / Tops3(以及类似于Lows)的值将相等,因此这些行最终会重叠并相互遮挡。 This is why I'm trying the 3D option. 这就是我正在尝试3D选项的原因。 Your idea of 3 panels of 2D graphs is a great suggestion I had not explored. 您对3个2D图表的想法是一个很好的建议,我没有探索过。

I'll give a try, but I would've thought a 3D plot would give me a clearer picture, especially a wireframe/mesh plot which would show values converging and I'd see the blue dot floating in 3D space at the point when the lines on the wireframe start making a peak or trough. 我会尝试一下,但我会认为3D绘图会给我一个更清晰的画面,尤其是线框/网格图,它会显示收敛的值,我会看到蓝点在3D空间中浮动线框上的线条开始形成高峰或低谷。 I just can't get it to work. 我无法让它发挥作用。

I've tried adapting matplotlib's Wireframe example but the plot I'm getting doesn't look like a wireframe at all. 我已经尝试过调整matplotlib的线框示例,但我得到的情节看起来并不像线框。

This is what I'm getting from the code below 这是我从下面的代码中得到的 在此输入图像描述 with just two of the data elements (Tops1 and Tops2): 只有两个数据元素(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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM