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')