mayavi points3d精神错乱

时间:2018-04-01 17:00:01

标签: python 3d mayavi.mlab

我有这样的代码:

import mayavi.mlab as mlab
import numpy as np
import random 

#white blackground
mlab.figure(fgcolor=(0., 0., 0.), bgcolor=(1, 1, 1))

x1 = y1 = z1 = size1 = []
# number of points
number = 21
for i in range(1,number):
        x1.append(random.randint(-10,11))
        y1.append(random.randint(-10,11))
        z1.append(random.randint(-10,11))
        size1.append(i)

#create spheres
mlab.points3d(x1, y1, z1, size1, resolution=30)
#render
mlab.show()

结果呈现的分数超过20: enter image description here

我做错了什么?为什么球体不在随机位置和球体数量? 当number == 2时,渲染为3个球体: enter image description here

1 个答案:

答案 0 :(得分:0)

好的,我懂了! 第一个错误是:

x1 = y1 = z1 = size1 = []

应该是:

x1 = []
y1 = []
z1 = []
size1 = []

最好在scale_factor=1

中添加mlab.points3d