I want to render some 3d spheres and to specify for each of it size and color. With size I have no problem:
import mayavi.mlab as mlab
import numpy as np
#white background
mlab.figure(fgcolor=(0., 0., 0.), bgcolor=(1, 1, 1))
#coordinates and sizes
x1 = np.array([27.340, 26.266, 26.913, 27.886, 25.112])
y1 = np.array([24.430, 25.413, 26.639, 26.463, 24.880])
z1 = np.array([2.614, 2.842, 3.531, 4.263, 3.649])
#initial size
size1 = np.array([7, 6, 6, 8, 6])
#decrease size of the spheres
size = np.true_divide(size1, 9)
#create spheres
mlab.points3d(x1, y1, z1, size, resolution=60, scale_factor=1)
#draw
mlab.show()
Gives OK spheres, but is impossible to control the colors.
I want to recolor depending of the size1
values
colors = []
for i in size1:
if i == 6 :
colors.append([0.5, 0.5, 0.5]) # grey
elif i == 7:
colors.append([0.1, 0.1, 0.9]) # blue
elif i == 8:
colors.append([0.9, 0.1, 0.1]) # red
I have seen similar problem as here but I use points3d
and there is no solution which I can use for my case.
How to define color for the each 3d point/sphere?