2016-08-23 170 views
1

我使用分散3D圖中matplotlib在python對於繪製下列數據的顏色,三維散點圖與matplotlib

 x    y   z  b2 
3.28912855713 4.64604863545 3.95526335139 1.0 
3.31252670518 4.65385917898 3.96834118896 1.0 

當情節爲2d,

fig = plt.figure() 
ax = fig.add_subplot(111) 
line =ax.scatter(x,y,c=b2,s=500,marker='*',edgecolors='none') 
cb = plt.colorbar(line) 

它產生以下圖像,這是完全正確的。現在 enter image description here

,我想繪製3D點,該代碼是:

fig = plt.figure() 
ax = fig.add_subplot(111,projection='3d') 
line = ax.scatter(x,y,z,c=b2,s=1500,marker='*',edgecolors='none',depthshade=0) 
cb = plt.colorbar(line) 

我也得到下面的圖形,這是不正確的,因爲顏色應該是綠色的像前一種情況(B2沒有按不會改變)。 enter image description here

我錯過了什麼嗎?

回答

3

可能不是。我不知道你使用的是什麼版本的Matplotlib,但是在某些時候這個問題存在一個錯誤,這個錯誤顯然仍然影響我今天使用的版本,即1.5.1(關於這個,請查看this question)。

針對您的問題調整@Yann解決方案應該可以解決該問題。我在我的電腦測試了它,結果是:在進入小區的

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 

x = [3.28912855713, 3.31252670518] 
y = [4.64604863545, 4.65385917898] 
z = [3.95526335139, 3.96834118896] 
b2 = [1, 1] 

fig = plt.figure() 
ax = fig.add_subplot(111,projection='3d') 
line = ax.scatter(x, y ,z , c=b2, s=1500, marker='*', edgecolors='none', depthshade=0) 
cb = plt.colorbar(line) 

def forceUpdate(event): 
    global line 
    line.changed() 

fig.canvas.mpl_connect('draw_event', forceUpdate) 

plt.show() 

圖像和旋轉後是:

3D matplotlib scatterplot with color

3D matplotlib scatterplot with color after rotation

+0

它曾與1.4。 3也。謝謝。 –