使用 Vispy 绘制东西后,得到的只有白色图像

After drawing something by using Vispy, getting only white image

如标题所示,仅打印白色图像。

下面是我的代码

import numpy as np
from vispy import io, scene

c = scene.SceneCanvas(keys='interactive', bgcolor='w', dpi=96)

view = c.central_widget.add_view()

xx, yy = np.arange(-1,1,.02),np.arange(-1,1,.02)
X,Y = np.meshgrid(xx,yy)
R = np.sqrt(X**2+Y**2)
Z = lambda t : 0.1*np.sin(10*R-2*np.pi*t)

surf = scene.visuals.SurfacePlot(xx, yy, Z(0), color=[0.5, 0.5, 0.5], shading='smooth')

view.add(surf)

img = c.render()
io.write_png("vispytest.png", img)

然后我得到 vispytest.png

我在 Linux.

上使用 Xvfb
Xvfb :1 -screen 0 2500x1500x24 -auth localhost

谢谢。

问题是相机的焦点问题,必须修改,类似下面的内容:

view.camera = scene.TurntableCamera(up='z', fov=60)

完整代码:

import numpy as np
from vispy import io, scene

c = scene.SceneCanvas(keys='interactive', bgcolor='w', dpi=96)

view = c.central_widget.add_view()
view.camera = scene.TurntableCamera(up='z', fov=60)

xx, yy = np.arange(-1,1,.02),np.arange(-1,1,.02)
X,Y = np.meshgrid(xx,yy)
R = np.sqrt(X**2+Y**2)
Z = lambda t : 0.1*np.sin(10*R-2*np.pi*t)

surf = scene.visuals.SurfacePlot(xx, yy, Z(0), color=[0.5, 0.5, 0.5], shading='smooth')

view.add(surf)

img = c.render()
io.write_png("vispytest.png", img)

vispytest.png