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

Zam*_*mbi 7 python r matplotlib mayavi mplot3d

我有一大堆数据,我试图在3D中表示希望发现一个模式.我花了很长时间阅读,研究和编码,但后来我意识到我的主要问题不是编程,而是实际上选择了一种可视化数据的方法.

Matplotlib的mplot3d提供了很多选项(线框,轮廓,填充轮廓等),MayaVi也是如此.但是有很多选择(每个都有自己的学习曲线),我几乎迷失了,不知道从哪里开始!所以我的问题基本上是你必须处理这些数据时使用哪种绘图方法?

我的数据是基于日期的.对于每个时间点,我绘制一个值(列表'Actual').

但是对于每个时间点,我也有一个上限,一个下限和一个中间点.这些限制和中点基于种子,在不同的平面上.

我希望在我的"实际"读数中发生重大变化时或之前发现该点或识别模式.是在所有飞机的上限都满足时?或者彼此接近?当实际值接触上/中/下限时?是否在一个平面上的Uppers触及另一架飞机的降落时?

在我粘贴的代码中,我将数据集简化为几个元素.我只是使用简单的散点图和线图,但由于数据集的大小(可能是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()
Run Code Online (Sandbox Code Playgroud)

我得到了这个情节,但它并没有帮助我看到任何共同关系.

在此输入图像描述 我不是数学家或科学家,所以我真正需要的是帮助选择FORMAT来可视化我的数据.有没有一种有效的方法在mplot3d中显示这个?或者你会使用MayaVis吗?在任何一种情况下,您将使用哪个库和类?

提前致谢.

gau*_*den 7

为了评论您的问题的可视化部分(而不是编程),我已经模拟了一些示例分面图,以建议您可能想要用来探索数据的替代方案.

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"))
Run Code Online (Sandbox Code Playgroud)

在第一个示例中,细蓝线是叠加在每个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
Run Code Online (Sandbox Code Playgroud)

折线图

在第二组中,每个面板具有实际值的散点图,相对于每个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
Run Code Online (Sandbox Code Playgroud)

相关

  • 这种将数据分解为子集并绘制2D子图的网格的方法的一些常见名称是"facet"(ggplot [Wickham])或"small multiples"(Tufte)或"条件图",通常缩写为"coplots"(格子)/Trellis [Cleveland,Chambers,Sarkar]) (2认同)