Ticket #5956: trac_5956-reviewer.patch

File trac_5956-reviewer.patch, 5.1 KB (added by kcrisman, 8 years ago)
  • sage/plot/graphics.py

    # 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  
    12781278        - ``figsize`` - (default: [8.0,6.0]) [width, height] inches. The
    12791279          maximum value of each of the width and the height can be 327
    12801280          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).
    12821282
    12831283        - ``fig_tight`` - (default: True) whether to clip the drawing
    12841284          tightly around drawn objects.  If True, then the resulting
     
    17591759
    17601760        TESTS:
    17611761
    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::
    17641766
    17651767            sage: p = ellipse((0,0),4,1)
    17661768            sage: p.show(figsize=[328,10],dpi=100)
     
    17861788            sig_off(). You might want to run Sage under gdb with 'sage
    17871789            -gdb' to debug this.  Sage will now terminate.
    17881790
     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
    17891804        """
    17901805
    17911806        # This option should not be passed on to save().
     
    21652180        self.axes_labels(l=axes_labels)
    21662181
    21672182        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)
    21682185            default_width, default_height=rcParams['figure.figsize']
    21692186            figsize=(figsize, default_height*figsize/default_width)
    21702187
     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
    21712192        if figure is None:
    21722193            figure=Figure(figsize=figsize)
    21732194       
  • sage/plot/plot.py

    diff --git a/sage/plot/plot.py b/sage/plot/plot.py
    a b  
    9595
    9696    sage: circle((1,1), 1) + plot(x^2, (x,0,5))
    9797
    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::
     98Notice that the aspect ratio of the above plot makes the plot very tall
     99because the plot adopts the default aspect ratio of the circle (to make
     100the circle appear like a circle).  We can change the aspect ratio to be
     101what we normally expect for a plot by explicitly asking for an
     102'automatic' aspect ratio::
    102103
    103104    sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), aspect_ratio='automatic')
    104105
    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::
     106The aspect ratio describes the apparently height/width ratio of a unit
     107square.  If you want the vertical units to be twice as big as the
     108horizontal units, specify an aspect ratio of 2::
    106109
    107110    sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), aspect_ratio=2)
    108111
    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``::
     112The ``figsize`` option adjusts the figure size.  The default figsize is
     1134.  To make a figure that is roughly twice as big, use ``figsize=8``::
    110114
    111115    sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), figsize=8)
    112116
    113 You can also give separate horizontal and vertical dimensions::
     117You can also give separate horizontal and vertical dimensions.  Both
     118will be measured in inches::
    114119
    115120    sage: show(circle((1,1), 1) + plot(x^2, (x,0,5)), figsize=[4,8])
    116121
     122However, do not make the figsize too big (e.g. one dimension greater
     123than 327 or both in the mid-200s) as this will lead to errors or crashes.
     124See :meth:`~sage.plot.graphics.Graphics.show` for full details.
     125
    117126Note that the axes will not cross if the data is not on both sides of
    118127both axes, even if it is quite close::
    119128