wiedzminYo
wiedzminYo

Reputation: 561

Matplotlib scatter 3d colors

My problem is that I wanted to draw a 0,0,0 point of this structure in diffrent color than all others points.But the plot present just contour in selected color and the inside of this ball is still in same color as others. I don't understand how this is working.

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

Upvotes: 1

Views: 22988

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339052

You can use the arguments edgecolor and facecolor to set the colors of the edges and faces.

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

Alternatively you can use the argument c to either set the color directly,

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

or to set a range of values that should be represented by color via a colormap. This last approach would also allow to put all points in a single scatterplot like so:

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

Upvotes: 7

Related Questions