【发布时间】:2018-05-08 11:16:09
【问题描述】:
我想渲染一些 3d 球体并为每个球体指定大小和颜色。尺寸我没问题:
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()
我想根据 size1 值重新着色
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
我看到过与here 类似的问题,但我使用的是points3d,并且没有可用于我的案例的解决方案。
如何为每个 3d 点/球体定义颜色?
【问题讨论】:
标签: python-2.7 colors 3d rendering mayavi