Ticket #4529: trac_4529-patch5.patch

File trac_4529-patch5.patch, 19.4 KB (added by kcrisman, 9 years ago)
  • sage/plot/arc.py

    # HG changeset patch
    # User Punarbasu Purkayastha <ppurka@gmail.com>
    # Date 1338275792 -28800
    # Node ID cd4c4c49133b66cbfad7c039fa4dbf649b595b35
    # Parent  aa8fcde356f86f6d02fc6c4ee8be1ca7be379ba5
    fix typos, add warnings, and fix aspect_ratio
      - fix `linear` to ``"linear"``, etc
      - add warnings to list_plot* and for noninteger base
      - change aspect_ratio to "automatic" for many plots in sage.plot.*
    
    diff --git a/sage/plot/arc.py b/sage/plot/arc.py
    a b  
    350350        NotImplementedError
    351351    """
    352352    from sage.plot.all import Graphics
     353
     354    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     355    # Otherwise matplotlib complains.
     356    scale = options.get('scale', None)
     357    if isinstance(scale, (list, tuple)):
     358        scale = scale[0]
     359    if scale == 'semilogy' or scale == 'semilogx':
     360        options['aspect_ratio'] = 'automatic'
     361
    353362    if len(center)==2:
    354363        if r2 is None: r2 = r1
    355364        g = Graphics()
  • sage/plot/circle.py

    diff --git a/sage/plot/circle.py b/sage/plot/circle.py
    a b  
    321321        1.0
    322322    """
    323323    from sage.plot.all import Graphics
     324
     325    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     326    # Otherwise matplotlib complains.
     327    scale = options.get('scale', None)
     328    if isinstance(scale, (list, tuple)):
     329        scale = scale[0]
     330    if scale == 'semilogy' or scale == 'semilogx':
     331        options['aspect_ratio'] = 'automatic'
     332
    324333    g = Graphics()
    325334    g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
    326335    g.add_primitive(Circle(center[0], center[1], radius, options))
  • sage/plot/contour_plot.py

    diff --git a/sage/plot/contour_plot.py b/sage/plot/contour_plot.py
    a b  
    507507        xy_data_array[mask] = numpy.ma.masked
    508508
    509509    g = Graphics()
     510
     511    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     512    # Otherwise matplotlib complains.
     513    scale = options.get('scale', None)
     514    if isinstance(scale, (list, tuple)):
     515        scale = scale[0]
     516    if scale == 'semilogy' or scale == 'semilogx':
     517        options['aspect_ratio'] = 'automatic'
     518
    510519    g._set_extra_kwds(Graphics._extract_kwds_for_show(options, ignore=['xmin', 'xmax']))
    511520    g.add_primitive(ContourPlot(xy_data_array, xrange, yrange, options))
    512521    return g       
     
    556565      ``basex`` sets the base of the logarithm along the horizontal
    557566      axis and ``basey`` sets the base along the vertical axis.
    558567
    559     - ``scale`` -- (default: `linear`) string. The scale of the axes.
    560       Possible values are `linear`, `loglog`, `semilogx`, `semilogy`.
     568    - ``scale`` -- (default: ``"linear"``) string. The scale of the axes.
     569      Possible values are ``"linear"``, ``"loglog"``, ``"semilogx"``,
     570      ``"semilogy"``.
    561571
    562572      The scale can be also be given as single argument that is a list
    563573      or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
    564574
    565       The `loglog` scale sets both the horizontal and vertical axes to
    566       logarithmic scale. The `semilogx` scale sets the horizontal axis
    567       to logarithmic scale. The `semilogy` scale sets the vertical axis
    568       to logarithmic scale. The `linear` scale is the default value
    569       when :class:`Graphics` is initialized.
     575      The ``"loglog"`` scale sets both the horizontal and vertical axes to
     576      logarithmic scale. The ``"semilogx"`` scale sets the horizontal axis
     577      to logarithmic scale. The ``"semilogy"`` scale sets the vertical axis
     578      to logarithmic scale. The ``"linear"`` scale is the default value
     579      when :class:`~sage.plot.graphics.Graphics` is initialized.
    570580
    571581    EXAMPLES:
    572582
     
    735745      ``basex`` sets the base of the logarithm along the horizontal
    736746      axis and ``basey`` sets the base along the vertical axis.
    737747
    738     - ``scale`` -- (default: `linear`) string. The scale of the axes.
    739       Possible values are `linear`, `loglog`, `semilogx`, `semilogy`.
     748    - ``scale`` -- (default: ``"linear"``) string. The scale of the axes.
     749      Possible values are ``"linear"``, ``"loglog"``, ``"semilogx"``,
     750      ``"semilogy"``.
    740751
    741752      The scale can be also be given as single argument that is a list
    742753      or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
    743754
    744       The `loglog` scale sets both the horizontal and vertical axes to
    745       logarithmic scale. The `semilogx` scale sets the horizontal axis
    746       to logarithmic scale. The `semilogy` scale sets the vertical axis
    747       to logarithmic scale. The `linear` scale is the default value
    748       when :class:`Graphics` is initialized.
     755      The ``"loglog"`` scale sets both the horizontal and vertical axes to
     756      logarithmic scale. The ``"semilogx"`` scale sets the horizontal axis
     757      to logarithmic scale. The ``"semilogy"`` scale sets the vertical axis
     758      to logarithmic scale. The ``"linear"`` scale is the default value
     759      when :class:`~sage.plot.graphics.Graphics` is initialized.
    749760
    750761
    751762    EXAMPLES:
     
    841852    cmap.set_under(incol)
    842853   
    843854    g = Graphics()
     855
     856    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     857    # Otherwise matplotlib complains.
     858    scale = options.get('scale', None)
     859    if isinstance(scale, (list, tuple)):
     860        scale = scale[0]
     861    if scale == 'semilogy' or scale == 'semilogx':
     862        options['aspect_ratio'] = 'automatic'
     863
    844864    g._set_extra_kwds(Graphics._extract_kwds_for_show(options, ignore=['xmin', 'xmax']))
    845865    g.add_primitive(ContourPlot(xy_data_array, xrange,yrange,
    846866                                dict(contours=[-1e307, 0, 1e307], cmap=cmap, fill=True, **options)))
  • sage/plot/disk.py

    diff --git a/sage/plot/disk.py b/sage/plot/disk.py
    a b  
    284284    """
    285285    from sage.plot.all import Graphics
    286286    g = Graphics()
     287
     288    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     289    # Otherwise matplotlib complains.
     290    scale = options.get('scale', None)
     291    if isinstance(scale, (list, tuple)):
     292        scale = scale[0]
     293    if scale == 'semilogy' or scale == 'semilogx':
     294        options['aspect_ratio'] = 'automatic'
     295
    287296    g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
    288297    g.add_primitive(Disk(point, radius, angle, options))
    289298    if options['legend_label']:
  • sage/plot/ellipse.py

    diff --git a/sage/plot/ellipse.py b/sage/plot/ellipse.py
    a b  
    282282    """
    283283    from sage.plot.all import Graphics
    284284    g = Graphics()
     285
     286    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     287    # Otherwise matplotlib complains.
     288    scale = options.get('scale', None)
     289    if isinstance(scale, (list, tuple)):
     290        scale = scale[0]
     291    if scale == 'semilogy' or scale == 'semilogx':
     292        options['aspect_ratio'] = 'automatic'
     293
    285294    g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
    286295    g.add_primitive(Ellipse(center[0],center[1],r1,r2,angle,options))
    287296    if options['legend_label']:
  • sage/plot/graphics.py

    diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
    a b  
    11331133        INPUT:
    11341134        - ``figure`` -- the matplotlib figure instance.
    11351135        - ``scale`` -- the scale of the figure. Values it can take are
    1136           `"linear"`, `"loglog"`, `"semilogx"`, `"semilogy"`. See
     1136          ``"linear"``, ``"loglog"``, ``"semilogx"``, ``"semilogy"``. See
    11371137          :meth:`show` for other options it can take.
    11381138        - ``base`` -- the base of the logarithm if a logarithmic scale is
    11391139          set. See :meth:`show` for the options it can take.
     
    13771377            `e`, or `sqrt(2)`, ticks will be formatted nicely at rational
    13781378            multiples of this constant.
    13791379
    1380           .. warning:: This should only be used with the ``ticks`` option
    1381              using nice rational multiples of that constant!
     1380          .. warning::
     1381
     1382             This should only be used with the ``ticks`` option using nice
     1383             rational multiples of that constant!
    13821384
    13831385          - If one of the entries is the string ``"latex"``, then the
    13841386            formatting will be nice typesetting of the ticks.  This is
     
    13951397          ``basex`` sets the base of the logarithm along the horizontal
    13961398          axis and ``basey`` sets the base along the vertical axis.
    13971399
    1398         - ``scale`` -- (default: `"linear"`) string. The scale of the axes.
     1400        - ``scale`` -- (default: ``"linear"``) string. The scale of the axes.
    13991401          Possible values are
    14001402
    1401           - `"linear"` -- linear scaling of both the axes
    1402           - `"loglog"` -- sets both the horizontal and vertical axes to
     1403          - ``"linear"`` -- linear scaling of both the axes
     1404          - ``"loglog"`` -- sets both the horizontal and vertical axes to
    14031405            logarithmic scale
    1404           - `"semilogx"` -- sets only the horizontal axis to logarithmic
     1406          - ``"semilogx"`` -- sets only the horizontal axis to logarithmic
    14051407            scale.
    1406           - `"semilogy"` -- sets only the vertical axis to logarithmic
     1408          - ``"semilogy"`` -- sets only the vertical axis to logarithmic
    14071409            scale.
    14081410
    14091411          The scale can be also be given as single argument that is a list
    14101412          or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
    14111413
    1412           Note: If the ``scale`` is `"linear"`, then irrespective of what
    1413           ``base`` is set to, it will default to 10 and will remain unused.
     1414          .. note::
     1415
     1416            - If the ``scale`` is ``"linear"``, then irrespective of what
     1417              ``base`` is set to, it will default to 10 and will remain
     1418              unused.
     1419
     1420            - Although it is possible to provide a noninteger ``base``, the
     1421              tick labeling and formatting is not ideal. Hence, in case you
     1422              do use noninteger ``base`` for the logarithm, then provide
     1423              your own tick formatter using the option ``tick_formatter``.
    14141424
    14151425        EXAMPLES::
    14161426       
     
    22562266           
    22572267            # Make the zero tick labels disappear if the axes cross
    22582268            # inside the picture, but only if log scale is not used
    2259             if (xmiddle and ymiddle and xscale == 'linear' and 
     2269            if (xmiddle and ymiddle and xscale == 'linear' and
    22602270                yscale == 'linear'):
    22612271                from sage.plot.plot import SelectiveFormatter
    22622272                subplot.yaxis.set_major_formatter(SelectiveFormatter(
  • sage/plot/plot.py

    diff --git a/sage/plot/plot.py b/sage/plot/plot.py
    a b  
    607607      ``basex`` sets the base of the logarithm along the horizontal
    608608      axis and ``basey`` sets the base along the vertical axis.
    609609
    610     - ``scale`` -- (default: `linear`) string. The scale of the axes.
    611       Possible values are `linear`, `loglog`, `semilogx`, `semilogy`.
     610    - ``scale`` -- (default: ``"linear"``) string. The scale of the axes.
     611      Possible values are ``"linear"``, ``"loglog"``, ``"semilogx"``,
     612      ``"semilogy"``.
    612613
    613614      The scale can be also be given as single argument that is a list
    614615      or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
    615616
    616       The `loglog` scale sets both the horizontal and vertical axes to
    617       logarithmic scale. The `semilogx` scale sets the horizontal axis
    618       to logarithmic scale. The `semilogy` scale sets the vertical axis
    619       to logarithmic scale. The `linear` scale is the default value
     617      The ``"loglog"`` scale sets both the horizontal and vertical axes to
     618      logarithmic scale. The ``"semilogx"`` scale sets the horizontal axis
     619      to logarithmic scale. The ``"semilogy"`` scale sets the vertical axis
     620      to logarithmic scale. The ``"linear"`` scale is the default value
    620621      when :class:`~sage.plot.graphics.Graphics` is initialized.
    621622
    622623    - ``xmin`` - starting x value
     
    632633
    633634    - ``legend_label`` - the label for this item in the legend
    634635
    635     APPEARANCE OPTIONS:
     636    .. note::
     637
     638        - If the ``scale`` is ``"linear"``, then irrespective of what
     639          ``base`` is set to, it will default to 10 and will remain unused.
     640
     641        - Although it is possible to provide a noninteger ``base``, the
     642          tick labeling and formatting is not ideal. Hence, in case you do
     643          use noninteger ``base`` for the logarithm, then provide your own
     644          tick formatter using the option ``tick_formatter``.
     645
     646    APPEARANCE OPTIONS:
    636647
    637648    The following options affect the appearance of
    638649    the line through the points on the graph of `X` (these are
     
    818829
    819830    ::
    820831
    821         sage: plot_loglog(exp, (1, 10), scale='loglog')   # both axes are log
     832        sage: plot_loglog(exp, (1, 10))   # both axes are log
    822833
    823834    ::
    824835
     
    16581669    Plotting in logarithmic scale is possible for 2D list plots.
    16591670    There are two different syntaxes available::
    16601671
    1661         sage: yl = [2**k for k in range(10)]
     1672        sage: yl = [2**k for k in range(20)]
    16621673        sage: list_plot(yl, scale='semilogy')       # log axis on vertical
    16631674
    16641675    ::
    16651676
    16661677        sage: list_plot_semilogy(yl)       # same
    16671678
     1679    .. warning::
     1680
     1681        If ``plotjoined`` is `False` then the axis that is in log scale
     1682        must have all points strictly positive. For instance, the following
     1683        plot will show no points in the figure since the points in the
     1684        horizontal axis starts from `(0,1)`.
     1685
    16681686    ::
    16691687
    16701688        sage: list_plot(yl, scale='loglog')         # both axes are log
    16711689
    1672     ::
    1673 
    1674         sage: list_plot_loglog(yl, base=2) # base of log is 2
     1690    Instead this will work. We drop the point `(0,1)`.::
     1691
     1692        sage: list_plot(zip(range(1,len(yl)), yl[1:]), scale='loglog')
     1693
     1694    We use :func:`list_plot_loglog` and plot in a different base.::
     1695
     1696        sage: list_plot_loglog(zip(range(1,len(yl)), yl[1:]), base=2)
    16751697
    16761698    We can also change the scale of the axes in the graphics just before
    16771699    displaying::
     
    17421764
    17431765    For all other inputs, look at the documentation of :func:`plot`.
    17441766
     1767    .. note::
     1768
     1769        - Although it is possible to provide a noninteger ``base``, the
     1770          tick labeling and formatting is not ideal. Hence, in case you do
     1771          use noninteger ``base`` for the logarithm, then provide your own
     1772          tick formatter using the option ``tick_formatter``.
     1773
    17451774    EXAMPLES::
    17461775
    17471776        sage: plot_loglog(exp, (1,10)) # plot in loglog scale with base 10
     
    17721801
    17731802    For all other inputs, look at the documentation of :func:`plot`.
    17741803
     1804    .. note::
     1805
     1806        - Although it is possible to provide a noninteger ``base``, the
     1807          tick labeling and formatting is not ideal. Hence, in case you do
     1808          use noninteger ``base`` for the logarithm, then provide your own
     1809          tick formatter using the option ``tick_formatter``.
     1810
    17751811    EXAMPLES::
    17761812
    17771813        sage: plot_semilogx(exp, (1,10)) # plot in semilogx scale, base 10
     
    17981834
    17991835    For all other inputs, look at the documentation of :func:`plot`.
    18001836
     1837    .. note::
     1838
     1839        - Although it is possible to provide a noninteger ``base``, the
     1840          tick labeling and formatting is not ideal. Hence, in case you do
     1841          use noninteger ``base`` for the logarithm, then provide your own
     1842          tick formatter using the option ``tick_formatter``.
     1843
    18011844    EXAMPLES::
    18021845
    18031846        sage: plot_semilogy(exp, (1,10)) # plot in semilogy scale, base 10
     
    18241867
    18251868    For all other inputs, look at the documentation of :func:`list_plot`.
    18261869
     1870
     1871    .. note::
     1872
     1873        - Although it is possible to provide a noninteger ``base``, the
     1874          tick labeling and formatting is not ideal. Hence, in case you do
     1875          use noninteger ``base`` for the logarithm, then provide your own
     1876          tick formatter using the option ``tick_formatter``.
     1877
    18271878    EXAMPLES::
    18281879
    18291880        sage: yl = [5**k for k in range(10)]; xl = [2**k for k in range(10)]
     
    18371888
    18381889        sage: list_plot_loglog(zip(xl, yl), base=(2,5))
    18391890
     1891    .. warning::
     1892
     1893        If ``plotjoined`` is `False` then the axis that is in log scale
     1894        must have all points strictly positive. For instance, the following
     1895        plot will show no points in the figure since the points in the
     1896        horizontal axis starts from `(0,1)`.
     1897
     1898    ::
     1899
     1900        sage: yl = [2**k for k in range(20)]
     1901        sage: list_plot_loglog(yl)
     1902
     1903    Instead this will work. We drop the point `(0,1)`.::
     1904
     1905        sage: list_plot_loglog(zip(range(1,len(yl)), yl[1:]))
     1906
    18401907    """
    18411908    return list_plot(data, plotjoined=plotjoined, scale='loglog', **kwds)
    18421909
     
    18531920
    18541921    For all other inputs, look at the documentation of :func:`list_plot`.
    18551922
     1923    .. note::
     1924
     1925        - Although it is possible to provide a noninteger ``base``, the
     1926          tick labeling and formatting is not ideal. Hence, in case you do
     1927          use noninteger ``base`` for the logarithm, then provide your own
     1928          tick formatter using the option ``tick_formatter``.
     1929
     1930
    18561931    EXAMPLES::
    18571932
    1858         sage: yl = [5**k for k in range(10)]
    1859         sage: list_plot_semilogx(yl) # plot in semilogx scale, base 10
     1933        sage: yl = [2**k for k in range(12)]
     1934        sage: list_plot_semilogx(zip(yl,yl))
     1935
     1936    .. warning::
     1937
     1938        If ``plotjoined`` is `False` then the horizontal axis must have all
     1939        points strictly positive. Otherwise the plot will come up empty.
     1940        For instance the following plot contains a point at `(0,1)`.
     1941
     1942    ::
     1943
     1944        sage: yl = [2**k for k in range(12)]
     1945        sage: list_plot_semilogx(yl) # plot is empty because of `(0,1)`
     1946
     1947    We remove `(0,1)` to fix this.::
     1948
     1949        sage: list_plot_semilogx(zip(range(1, len(yl)), yl[1:]))
    18601950
    18611951    ::
    18621952
     
    18781968
    18791969    For all other inputs, look at the documentation of :func:`list_plot`.
    18801970
     1971    .. note::
     1972
     1973        - Although it is possible to provide a noninteger ``base``, the
     1974          tick labeling and formatting is not ideal. Hence, in case you do
     1975          use noninteger ``base`` for the logarithm, then provide your own
     1976          tick formatter using the option ``tick_formatter``.
     1977
    18811978    EXAMPLES::
    18821979
    1883         sage: yl = [5**k for k in range(10)]
     1980        sage: yl = [2**k for k in range(12)]
    18841981        sage: list_plot_semilogy(yl) # plot in semilogy scale, base 10
    18851982
     1983    .. warning::
     1984
     1985        If ``plotjoined`` is `False` then the vertical axis must have all
     1986        points strictly positive. Otherwise the plot will come up empty.
     1987        For instance the following plot contains a point at `(1,0)`.
     1988
    18861989    ::
    18871990
    1888         sage: list_plot_semilogy(yl, base=5) # with base 5
     1991        sage: xl = [2**k for k in range(12)]; yl = range(len(xl))
     1992        sage: list_plot_semilogy(zip(xl,yl)) # plot empty due to (1,0)
     1993
     1994    We remove `(1,0)` to fix this.::
     1995
     1996        sage: list_plot_semilogy(zip(xl[1:],yl[1:]))
     1997
     1998
     1999    ::
     2000
     2001        sage: list_plot_semilogy(yl, base=2) # with base 2
    18892002
    18902003    """
    18912004    return list_plot(data, plotjoined=plotjoined, scale='semilogy', **kwds)
  • sage/plot/polygon.py

    diff --git a/sage/plot/polygon.py b/sage/plot/polygon.py
    a b  
    364364            options["thickness"] = 1
    365365    xdata, ydata = xydata_from_point_list(points)
    366366    g = Graphics()
     367
     368    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     369    # Otherwise matplotlib complains.
     370    scale = options.get('scale', None)
     371    if isinstance(scale, (list, tuple)):
     372        scale = scale[0]
     373    if scale == 'semilogy' or scale == 'semilogx':
     374        options['aspect_ratio'] = 'automatic'
     375
    367376    g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
    368377    g.add_primitive(Polygon(xdata, ydata, options))
    369378    if options['legend_label']: