2017-04-03 63 views
1

我的問題是,我想繪製一個0,0,0這個結構的不同顏色比所有其他points.But圖呈現輪廓在選定的顏色和這個球的內部仍然與其他顏色相同。 我不明白這是如何工作的。Matplotlib scatter 3d colors

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



fig = plt.figure() 
ax = fig.gca(projection='3d') 
ax.set_aspect("equal") 

for x in range(-count,count+1): 
    for y in range(-count,count+1): 
     for z in range(-count,count+1): 
      if x == 0 and y == 0 and z == 0: 
       ax.scatter(x,y,z, color="g",s=100) #here is the problem 
      elif ((x+y+z+3*count)%2) == 0: 
       ax.scatter(*zip([x,y,z]), color="r") 
      else: 
       ax.scatter(*zip([x,y,z]), color="b") 

    plt.show() 

plot of cubic structure

回答

4

您可以使用參數edgecolorfacecolor設置邊和麪的顏色。

ax.scatter(x,y,z, s=100, edgecolor="r", facecolor="gold") 

或者,也可以使用參數c以直接設置顏色,

ax.scatter(x,y,z, s=100, c="limegreen") 

,或者設定的範圍應該通過經由顏色表的顏色來表示的值的。這最後的解決方案也可以把所有的點在一個單一的散點圖,像這樣:

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

fig = plt.figure() 
ax = fig.gca(projection='3d') 
ax.set_aspect("equal") 

count = 2 
x = range(-count,count+1) 
X,Y,Z = np.meshgrid(x,x,x) 

c = np.zeros_like(X, dtype=np.float) 
c[((X+Y+Z+3*count)%2) == 0] = 0.5 
c[count,count,count] = 1 

s = np.ones_like(X)*25 
s[count,count,count] = 100 
ax.scatter(X,Y,Z, c=c,s=s, cmap="brg") 

plt.show() 

enter image description here

+0

我已經試過這個解決方案,但沒有奏效。 – wiedzminYo

+0

我增加了兩個更多的選擇。如果他們不工作,你可能會有一個真正舊版本的matplotlib,可能會考慮更新。 – ImportanceOfBeingErnest

+0

你說得對,我只是升級了我的matplotlib版本。謝謝你的幫助。 – wiedzminYo