# contour_plot and figsize issue

Hello!

I am trying to make contour_plot of function and then get result image with custom size using show and keywork figsize.

The strange thing: this code actually ignores figsize keyword:

x,y = var('x,y')
contour_plot(cos(x^2+y^2), (x, -4, 4), (y, -4, 4)).show(xmin=-4,xmax=4,ymin=-4,ymax=4,figsize=(10,6))


But this one respects:

(point((0,0))+contour_plot(cos(x^2+y^2), (x, -4, 4), (y, -4, 4))).show(xmin=-4,xmax=4,ymin=-4,ymax=4,figsize=(8,2))


How to set figsize for contour_plot properly?

edit retag close merge delete

Sort by » oldest newest most voted

By default, the contour plot has an aspect ratio of 1. To instead fill up the entire figure, set the aspect ratio to 'automatic'. This is what is happening in your second example: the aspect ratio of the entire figure is getting changed by the point graphic.

x,y = var('x,y')
contour_plot(cos(x^2+y^2), (x, -4, 4), (y, -4, 4)).show(xmin=-4,xmax=4,ymin=-4,ymax=4,figsize=(10,6),aspect_ratio='automatic')


Here's a more detailed answer about why the actual image size was getting cropped. By default, the image is created at the proper figure size, but then is cropped to the actual size of the plot within the figure (i.e., the image returned is "tightly" cropped around the graphic). You can turn off this cropping by setting fig_tight=False. This is documented in the show options. In the example below, the aspect ratio is not changed, but the resulting image file is still the requested size.

x,y = var('x,y')
contour_plot(cos(x^2+y^2), (x, -4, 4), (y, -4, 4)).show(xmin=-4,xmax=4,ymin=-4,ymax=4,figsize=(10,6),fig_tight=False)


If you want the contour plot to fill the figure, and still want an image that is exactly the right size, you'll need to change the aspect ratio to 'automatic' and use the fig_tight parameter.

x,y = var('x,y')
contour_plot(cos(x^2+y^2), (x, -4, 4), (y, -4, 4)).show(xmin=-4,xmax=4,ymin=-4,ymax=4,figsize=(10,6),fig_tight=False,aspect_ratio='automatic')

more

Thank you for such a good and full answer! The problem is solved.

( 2011-12-16 04:41:05 -0600 )edit

## Stats

Seen: 140 times

Last updated: Dec 16 '11