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()
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.