This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Remove White Space When Plotting

0 votes

The following generates an image.

 from dolfin import *
 mesh_obj = UnitSquareMesh( 20,20 )
 V = FunctionSpace( mesh_obj, "CG", 1 )
 v = Function( V )

plot( v, mode = "color", scalarbar = False ).write_png( "something" )

This plot has white space around the object being plotted. Setting the parameters window_height, window width just rescales everything, including the white space. Can I get rid of the white space? I want to use the images in a paper and I don't want to waste too much space.

Thanks!!!

asked Apr 7, 2016 by Yair Daon FEniCS User (1,350 points)

1 Answer

+2 votes
 
Best answer

The VTKPlotter object returned by plot has a zoom method which you can use to zoom into the image, which might help reduce the amount of white space you have:

plotter = plot(u, window_height=500, window_width=700)
plotter.zoom(1.5) # zoom into the image a bit to reduce white space
plotter.write_png("image") # save image

This might require a bit of trial-and-error to figure out the right parameters though.

Alternatively, depending on your image, it might be more convenient to crop out the white space using image editing software (there are automated utilities such as ImageMagick which can do batch trimming of white space).

answered Apr 7, 2016 by FF FEniCS User (4,630 points)
selected Apr 8, 2016 by Yair Daon

AWESOME!!! Thank you!

...