ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 16 Dec 2011 04:41:05 -0600contour_plot and figsize issuehttp://ask.sagemath.org/question/8567/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?Fri, 16 Dec 2011 01:26:56 -0600http://ask.sagemath.org/question/8567/contour_plot-and-figsize-issue/Answer by Jason Grout for <p>Hello!</p>
<p>I am trying to make contour_plot of function and then get result image with custom size using <strong>show</strong> and keywork <strong>figsize</strong>.</p>
<p>The strange thing: this code actually ignores <strong>figsize</strong> keyword:</p>
<pre><code>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))
</code></pre>
<p>But this one respects:</p>
<pre><code>(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))
</code></pre>
<p>How to set figsize for contour_plot properly?</p>
http://ask.sagemath.org/question/8567/contour_plot-and-figsize-issue/?answer=13027#post-id-13027By 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](http://www.sagemath.org/doc/reference/sage/plot/plot.html#sage.plot.plot.Graphics.show). 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')
Fri, 16 Dec 2011 02:34:15 -0600http://ask.sagemath.org/question/8567/contour_plot-and-figsize-issue/?answer=13027#post-id-13027Comment by Eugene for <p>By default, the contour plot has an aspect ratio of 1. To instead fill up the entire figure, set the aspect ratio to '<code>automatic</code>'. This is what is happening in your second example: the aspect ratio of the entire figure is getting changed by the point graphic.</p>
<pre><code>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')
</code></pre>
<p>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 <code>fig_tight=False</code>. This is documented in the <a href="http://www.sagemath.org/doc/reference/sage/plot/plot.html#sage.plot.plot.Graphics.show">show options</a>. In the example below, the aspect ratio is not changed, but the resulting image file is still the requested size.</p>
<pre><code>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)
</code></pre>
<p>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 <code>'automatic'</code> and use the <code>fig_tight</code> parameter.</p>
<pre><code>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')
</code></pre>
http://ask.sagemath.org/question/8567/contour_plot-and-figsize-issue/?comment=20698#post-id-20698Thank you for such a good and full answer! The problem is solved.Fri, 16 Dec 2011 04:41:05 -0600http://ask.sagemath.org/question/8567/contour_plot-and-figsize-issue/?comment=20698#post-id-20698