# HG changeset patch
# User Karl-Dieter Crisman <kcrisman@gmail.com>
# 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
|
b
|
|
1278 | 1278 | - ``figsize`` - (default: [8.0,6.0]) [width, height] inches. The |
1279 | 1279 | maximum value of each of the width and the height can be 327 |
1280 | 1280 | inches, at the default ``dpi`` of 100 dpi, which is just shy of |
1281 | | the maximum allowed value of 32768 dots per inch. |
| 1281 | the maximum allowed value of 32768 dots (pixels). |
1282 | 1282 | |
1283 | 1283 | - ``fig_tight`` - (default: True) whether to clip the drawing |
1284 | 1284 | tightly around drawn objects. If True, then the resulting |
… |
… |
|
1759 | 1759 | |
1760 | 1760 | TESTS: |
1761 | 1761 | |
1762 | | The figsize width and height parameters must be less than 328 |
1763 | | inches each, corresponding to the maximum allowed dpi of 32768.:: |
| 1762 | The figsize width and height parameters (at default dpi) must be |
| 1763 | less than 328 inches each, corresponding to the maximum allowed |
| 1764 | pixels in each direction of 32768. See :trac:`5956` for more about |
| 1765 | the next several tests:: |
1764 | 1766 | |
1765 | 1767 | sage: p = ellipse((0,0),4,1) |
1766 | 1768 | sage: p.show(figsize=[328,10],dpi=100) |
… |
… |
|
1786 | 1788 | sig_off(). You might want to run Sage under gdb with 'sage |
1787 | 1789 | -gdb' to debug this. Sage will now terminate. |
1788 | 1790 | |
| 1791 | The following tests ensure we give a good error message for |
| 1792 | negative figsizes:: |
| 1793 | |
| 1794 | sage: P = plot(x^2,(x,0,1)) |
| 1795 | sage: P.show(figsize=[-1,1]) |
| 1796 | Traceback (most recent call last): |
| 1797 | ... |
| 1798 | AssertionError: figsize should be positive numbers, not -1 and 1 |
| 1799 | sage: P.show(figsize=-1) |
| 1800 | Traceback (most recent call last): |
| 1801 | ... |
| 1802 | AssertionError: figsize should be positive, not -1 |
| 1803 | |
1789 | 1804 | """ |
1790 | 1805 | |
1791 | 1806 | # This option should not be passed on to save(). |
… |
… |
|
2165 | 2180 | self.axes_labels(l=axes_labels) |
2166 | 2181 | |
2167 | 2182 | if figsize is not None and not isinstance(figsize, (list, tuple)): |
| 2183 | # in this case, figsize is a number and should be positive |
| 2184 | assert figsize > 0, "figsize should be positive, not {0}".format(figsize) |
2168 | 2185 | default_width, default_height=rcParams['figure.figsize'] |
2169 | 2186 | figsize=(figsize, default_height*figsize/default_width) |
2170 | 2187 | |
| 2188 | if figsize is not None: |
| 2189 | # then the figsize should be two positive numbers |
| 2190 | assert figsize[0] > 0 and figsize[1] > 0, "figsize should be positive numbers, not {0} and {1}".format(figsize[0],figsize[1]) |
| 2191 | |
2171 | 2192 | if figure is None: |
2172 | 2193 | figure=Figure(figsize=figsize) |
2173 | 2194 | |
diff --git a/sage/plot/plot.py b/sage/plot/plot.py
a
|
b
|
|
95 | 95 | |
96 | 96 | sage: circle((1,1), 1) + plot(x^2, (x,0,5)) |
97 | 97 | |
98 | | Notice that the aspect ratio of the above plot makes the plot very tall because |
99 | | the plot adopts the default aspect ratio of the circle (to make the circle appear |
100 | | like a circle). We can change the aspect ratio to be what we normally expect for a plot |
101 | | by explicitly asking for an 'automatic' aspect ratio:: |
| 98 | Notice that the aspect ratio of the above plot makes the plot very tall |
| 99 | because the plot adopts the default aspect ratio of the circle (to make |
| 100 | the circle appear like a circle). We can change the aspect ratio to be |
| 101 | what we normally expect for a plot by explicitly asking for an |
| 102 | 'automatic' aspect ratio:: |
102 | 103 | |
103 | 104 | sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), aspect_ratio='automatic') |
104 | 105 | |
105 | | 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:: |
| 106 | The aspect ratio describes the apparently height/width ratio of a unit |
| 107 | square. If you want the vertical units to be twice as big as the |
| 108 | horizontal units, specify an aspect ratio of 2:: |
106 | 109 | |
107 | 110 | sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), aspect_ratio=2) |
108 | 111 | |
109 | | 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``:: |
| 112 | The ``figsize`` option adjusts the figure size. The default figsize is |
| 113 | 4. To make a figure that is roughly twice as big, use ``figsize=8``:: |
110 | 114 | |
111 | 115 | sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), figsize=8) |
112 | 116 | |
113 | | You can also give separate horizontal and vertical dimensions:: |
| 117 | You can also give separate horizontal and vertical dimensions. Both |
| 118 | will be measured in inches:: |
114 | 119 | |
115 | 120 | sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), figsize=[4,8]) |
116 | 121 | |
| 122 | However, do not make the figsize too big (e.g. one dimension greater |
| 123 | than 327 or both in the mid-200s) as this will lead to errors or crashes. |
| 124 | See :meth:`~sage.plot.graphics.Graphics.show` for full details. |
| 125 | |
117 | 126 | Note that the axes will not cross if the data is not on both sides of |
118 | 127 | both axes, even if it is quite close:: |
119 | 128 | |