2012-02-06 73 views
3

我試圖讓從X,Y,Z點列表中的3D圖,我想這取決於第四可變RHO值繪製顏色的顏色。的Python matplotlib:PLOT3D格式與4D

目前,我有;

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
ax.plot3D(cell_x, cell_y, cell_z, linestyle='None', marker='o', markersize = 5, antialiased=True) 
ax.set_xlim3d(0.45, 0.55) 
ax.set_ylim3d(0.45, 0.55) 
ax.set_zlim3d(0.45, 0.55) 

如何添加cell_rho(我的第四個數組)作爲我的X,Y,Z點的顏色? (例如對於噴射色彩映射)。

非常感謝。

編輯:我不能用散點圖,因爲我的18000點相比,只有標記來PLOT3D格式散點圖是非常慢的。

+0

這些方針的東西:http://stackoverflow.com/questions/9134879/how-to-plot-a-multicolored-curve-using-a-single-plot-command-in-matplotlib? – 2012-02-06 18:22:11

+0

即使這樣,我不明白如何將rho轉換爲可以傳遞給我的情節3D的「顏色」選項的值... – Vincent 2012-02-06 18:33:20

+0

您是否嘗試混合多彩線(http://www.scipy .org/Cookbook/Matplotlib/MulticoloredLine)和3d線(http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutorial.html#line-plots)? – matt 2012-02-06 20:24:46

回答

5

如果你想顯示一個簡單的3D散點圖,你就不能使用scatter
例如,

x, y, z = randn(100), randn(100), randn(100) 
fig = plt.figure() 
from mpl_toolkits.mplot3d import Axes3D 
ax = fig.add_subplot(111, projection='3d') 
ax.scatter(x, y, z, c=randn(100)) 
plt.show() 

(我python -pylab下運行上面的代碼。)

enter image description here

看來,恰恰相反,與plot3D您必須將第四個維度轉換爲RGB元組。

+0

我的問題是,我的18000點散點圖比PLOT3D格式只有標記方法要慢... – Vincent 2012-02-07 09:03:07