4

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.

jvtrudel
  • 1,235
  • 3
  • 15
  • 28

2 Answers2

7

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)
jvtrudel
  • 1,235
  • 3
  • 15
  • 28
  • 1
    This answer didn't work for me with vispy 0.3.0 (the latest version I found as a conda package for win64 at https://binstar.org/search?q=type%3Aconda+vispy). The line `img=canvas.render()` returned: `'SceneCanvas' object has no attribute 'render'`. What version was being used here? – Rich Signell Apr 02 '15 at 19:17
  • Vispy has been modified extensively since my post. I'll have a look to it. – jvtrudel Apr 02 '15 at 19:45
  • It still work for me. Could you report your bug ?https://github.com/vispy/vispy/issues – jvtrudel Apr 02 '15 at 19:49
  • 1
    Okay, we built the latest version 0.4.0-DEV from master and it worked. Conda packages for 0.4.0-DEV for linux64, win32 and win64 are here: http://binstar.org/ioos/vispy – Rich Signell Apr 03 '15 at 09:53
1

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)
Martin R.
  • 1,554
  • 17
  • 16