enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.28k stars 282 forks source link

mlab.savefig saves wrong resolution (for first two images in loop) #1288

Open smiet opened 5 months ago

smiet commented 5 months ago

When using mlab.savefig(<imagename>, size=(x, y)) the resolution of the saved image is about 10x that specified:

from mayavi import mlab

f = mlab.figure()
mlab.test_plot3d()
mlab.savefig('savetest.png', size=(100,80))

resolution:

$ identify -format '%f %w x %h \n' savetest.png 
savetest.png 1200 x 891 

When using mlab.savefig() in a for loop to generate a series of images, the first two will have this wrong resolution, the rest will be correct. MWE:

from mayavi import mlab

f = mlab.figure()
for n in range(10):
    mlab.test_contour3d()
    mlab.draw()
    mlab.savefig(f'iteration_{n}.png', size=(100, 80))
    mlab.clf()

The resolutions are (assuming ImageMagick is installed)

$ identify -format '%f %w x %h \n' iteration_*
iteration_0.png 1200 x 891 
iteration_1.png 1200 x 891 
iteration_2.png 99 x 78 
iteration_3.png 99 x 78 
iteration_4.png 99 x 78 
iteration_5.png 99 x 78 
iteration_6.png 99 x 78 
iteration_7.png 99 x 78 
iteration_8.png 99 x 78 
iteration_9.png 99 x 78 

This also occurs when using the virtual frame buffer http://docs.enthought.com/mayavi/mayavi/tips.html#rendering-using-the-virtual-framebuffer.

when using the direct frame buffer, I see the rendering process uses the whole window, and switches to a much smaller section after the third image.