简体   繁体   中英

How to export VisPy result as png image

Is it possible to save images made with VisPy? Maybe using vispy.io.imsave or vispy.write_png?

Also, it is possible to plot matplotlib figures in vispy using vispy.mpl_plot but is it possible to use a vispy image in matplotlib?

In any case, I would need to generate an image object with VisPy but I did not find any example of that.

Here is a minimal example. Use canvas.render to create an image, then export it with io.write_png:

import vispy.plot as vp 
import vispy.io as io

# Create a canvas showing plot data 
canvas = vp.plot([1, 6, 2, 4, 3, 8, 5, 7, 6, 3])

# Use render to generate an image object
img=canvas.render()

# Use write_png to export your wonderful plot as png ! 
io.write_png("wonderful.png",img)

Here is an updated version jvtrudel's of answer (working with vispy 0.5.0-dev):

The official demo https://github.com/vispy/vispy/blob/master/examples/basics/plotting/export.py does something very similar, and a stripped down version adjusted to export a png could look like this:

import vispy.plot as vp
import vispy.io as io

fig = vp.Fig(show=False)
fig[0, 0].plot([1, 6, 2, 4, 3, 8, 5, 7, 6, 3])

image = fig.render()
io.write_png("wonderful.png",image)

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