# HG changeset patch
# User Karl-Dieter Crisman
# Date 1364005243 14400
# Node ID 9ba55a30540032b14af752a93f9d28e01084d605
# Parent be6c6fd1cd4733fe2d698e282c52850df5185abd
Trac 5956 additional patch adding doc, tests, and assertion for figsize
diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
--- a/sage/plot/graphics.py
+++ b/sage/plot/graphics.py
@@ -1278,7 +1278,7 @@
- ``figsize`` - (default: [8.0,6.0]) [width, height] inches. The
maximum value of each of the width and the height can be 327
inches, at the default ``dpi`` of 100 dpi, which is just shy of
- the maximum allowed value of 32768 dots per inch.
+ the maximum allowed value of 32768 dots (pixels).
- ``fig_tight`` - (default: True) whether to clip the drawing
tightly around drawn objects. If True, then the resulting
@@ -1759,8 +1759,10 @@
TESTS:
- The figsize width and height parameters must be less than 328
- inches each, corresponding to the maximum allowed dpi of 32768.::
+ The figsize width and height parameters (at default dpi) must be
+ less than 328 inches each, corresponding to the maximum allowed
+ pixels in each direction of 32768. See :trac:`5956` for more about
+ the next several tests::
sage: p = ellipse((0,0),4,1)
sage: p.show(figsize=[328,10],dpi=100)
@@ -1786,6 +1788,19 @@
sig_off(). You might want to run Sage under gdb with 'sage
-gdb' to debug this. Sage will now terminate.
+ The following tests ensure we give a good error message for
+ negative figsizes::
+
+ sage: P = plot(x^2,(x,0,1))
+ sage: P.show(figsize=[-1,1])
+ Traceback (most recent call last):
+ ...
+ AssertionError: figsize should be positive numbers, not -1 and 1
+ sage: P.show(figsize=-1)
+ Traceback (most recent call last):
+ ...
+ AssertionError: figsize should be positive, not -1
+
"""
# This option should not be passed on to save().
@@ -2165,9 +2180,15 @@
self.axes_labels(l=axes_labels)
if figsize is not None and not isinstance(figsize, (list, tuple)):
+ # in this case, figsize is a number and should be positive
+ assert figsize > 0, "figsize should be positive, not {0}".format(figsize)
default_width, default_height=rcParams['figure.figsize']
figsize=(figsize, default_height*figsize/default_width)
+ if figsize is not None:
+ # then the figsize should be two positive numbers
+ assert figsize[0] > 0 and figsize[1] > 0, "figsize should be positive numbers, not {0} and {1}".format(figsize[0],figsize[1])
+
if figure is None:
figure=Figure(figsize=figsize)
diff --git a/sage/plot/plot.py b/sage/plot/plot.py
--- a/sage/plot/plot.py
+++ b/sage/plot/plot.py
@@ -95,25 +95,34 @@
sage: circle((1,1), 1) + plot(x^2, (x,0,5))
-Notice that the aspect ratio of the above plot makes the plot very tall because
-the plot adopts the default aspect ratio of the circle (to make the circle appear
-like a circle). We can change the aspect ratio to be what we normally expect for a plot
-by explicitly asking for an 'automatic' aspect ratio::
+Notice that the aspect ratio of the above plot makes the plot very tall
+because the plot adopts the default aspect ratio of the circle (to make
+the circle appear like a circle). We can change the aspect ratio to be
+what we normally expect for a plot by explicitly asking for an
+'automatic' aspect ratio::
sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), aspect_ratio='automatic')
-The aspect ratio describes the apparently height/width ratio of a unit square. If you want the vertical units to be twice as big as the horizontal units, specify an aspect ratio of 2::
+The aspect ratio describes the apparently height/width ratio of a unit
+square. If you want the vertical units to be twice as big as the
+horizontal units, specify an aspect ratio of 2::
sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), aspect_ratio=2)
-The ``figsize`` option adjusts the figure size. The default figsize is 4. To make a figure that is roughly twice as big, use ``figsize=8``::
+The ``figsize`` option adjusts the figure size. The default figsize is
+4. To make a figure that is roughly twice as big, use ``figsize=8``::
sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), figsize=8)
-You can also give separate horizontal and vertical dimensions::
+You can also give separate horizontal and vertical dimensions. Both
+will be measured in inches::
sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), figsize=[4,8])
+However, do not make the figsize too big (e.g. one dimension greater
+than 327 or both in the mid-200s) as this will lead to errors or crashes.
+See :meth:`~sage.plot.graphics.Graphics.show` for full details.
+
Note that the axes will not cross if the data is not on both sides of
both axes, even if it is quite close::