Matplotlib散射3d颜色

时间:2017-04-03 19:21:41

标签: python matplotlib

我的问题是我想用不同颜色绘制这个结构的0,0,0点而不是所有其他点。但是绘图只显示所选颜色的轮廓,并且该球的内部仍然是与其他。 我不明白这是如何运作的。

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

1 个答案:

答案 0 :(得分: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