简体   繁体   中英

After drawing something by using Vispy, getting only white image

As the title, only white image is printed.

below is my codes

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)

And I get vispytest.png 在此处输入图片说明

I'm using Xvfb on Linux.

Xvfb :1 -screen 0 2500x1500x24 -auth localhost

Thank you.

The problem is the focus of the camera, must modify, something similar to the following:

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

Complete code:

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

在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM