Ticket #4529: trac_4529-patch3.patch

File trac_4529-patch3.patch, 13.1 KB (added by kcrisman, 9 years ago)
  • sage/plot/all.py

    # HG changeset patch
    # User Punarbasu Purkayastha <ppurka@gmail.com>
    # Date 1337533730 -28800
    # Node ID 0addabc5061b204a19626f463cba0225b469486c
    # Parent  9161e5333271aa7d649f365b0dcb069e46fe8f2c
     - add some examples for log scale to other user facing functions
     - also add a minor check in parametric_plot
     - finally add loglog_*, semilogx_*, semilogy_* plots
    
    diff --git a/sage/plot/all.py b/sage/plot/all.py
    a b  
    11from graphics import show_default, Graphics, is_Graphics
    22from plot import plot, graphics_array, list_plot, parametric_plot, polar_plot
     3from plot import plot_loglog, plot_semilogx, plot_semilogy
     4from plot import list_plot_loglog, list_plot_semilogx, list_plot_semilogy
    35from line import line, line2d
    46from arrow import arrow, arrow2d
    57from bar_chart import bar_chart
  • sage/plot/contour_plot.py

    diff --git a/sage/plot/contour_plot.py b/sage/plot/contour_plot.py
    a b  
    550550
    551551    - ``legend_label`` -- the label for this item in the legend
    552552
     553    - ``base`` - (default: 10) the base of the logarithm if
     554      a logarithmic scale is set. This must be greater than 1. The base
     555      can be also given as a list or tuple ``(basex, basey)``.
     556      ``basex`` sets the base of the logarithm along the horizontal
     557      axis and ``basey`` sets the base along the vertical axis.
     558
     559    - ``scale`` -- (default: `linear`) string. The scale of the axes.
     560      Possible values are `linear`, `loglog`, `semilogx`, `semilogy`.
     561
     562      The scale can be also be given as single argument that is a list
     563      or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
     564
     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.
     570
    553571    EXAMPLES:
    554572
    555573    A simple circle with a radius of 2. Note that
     
    629647
    630648        sage: implicit_plot(lambda x,y: x^2+y^2-2, (x,-3,3), (y,-3,3), fill=True, plot_points=500) # long time
    631649
     650    An example of an implicit plot on 'loglog' scale::
     651
     652        sage: implicit_plot(x^2+y^2 == 200, (x,1,200), (y,1,200), scale='loglog')
     653
    632654    TESTS::
    633655
    634656        sage: f(x,y) = x^2 + y^2 - 2
     
    707729 
    708730    - ``legend_label`` -- the label for this item in the legend
    709731
     732    - ``base`` - (default: 10) the base of the logarithm if
     733      a logarithmic scale is set. This must be greater than 1. The base
     734      can be also given as a list or tuple ``(basex, basey)``.
     735      ``basex`` sets the base of the logarithm along the horizontal
     736      axis and ``basey`` sets the base along the vertical axis.
     737
     738    - ``scale`` -- (default: `linear`) string. The scale of the axes.
     739      Possible values are `linear`, `loglog`, `semilogx`, `semilogy`.
     740
     741      The scale can be also be given as single argument that is a list
     742      or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
     743
     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.
     749
    710750
    711751    EXAMPLES:
    712752
     
    766806
    767807        sage: region_plot(s>0,(s,-2,2),(t,-2,2))
    768808
     809    An example of a region plot in 'loglog' scale::
     810
     811        sage: region_plot(x^2+y^2<100, (x,1,10), (y,1,10), scale='loglog')
     812
    769813    """
    770814
    771815    from sage.plot.all import Graphics
  • sage/plot/plot.py

    diff --git a/sage/plot/plot.py b/sage/plot/plot.py
    a b  
    590590      before the adaptive refinement code considers it significant.  See the
    591591      documentation further below for more information, starting at "the
    592592      algorithm used to insert".
    593    
     593
     594    - ``base`` - (default: 10) the base of the logarithm if
     595      a logarithmic scale is set. This must be greater than 1. The base
     596      can be also given as a list or tuple ``(basex, basey)``.
     597      ``basex`` sets the base of the logarithm along the horizontal
     598      axis and ``basey`` sets the base along the vertical axis.
     599
     600    - ``scale`` -- (default: `linear`) string. The scale of the axes.
     601      Possible values are `linear`, `loglog`, `semilogx`, `semilogy`.
     602
     603      The scale can be also be given as single argument that is a list
     604      or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
     605
     606      The `loglog` scale sets both the horizontal and vertical axes to
     607      logarithmic scale. The `semilogx` scale sets the horizontal axis
     608      to logarithmic scale. The `semilogy` scale sets the vertical axis
     609      to logarithmic scale. The `linear` scale is the default value
     610      when :class:`~sage.graphics.Graphics` is initialized.
     611
    594612    - ``xmin`` - starting x value
    595613
    596614    - ``xmax`` - ending x value
     
    776794
    777795    Note that the independent variable may be omitted if there is no
    778796    ambiguity::
    779    
     797
    780798        sage: plot(sin(1/x), (-1, 1))
    781    
     799
     800    Plotting in logarithmic scale is possible for 2D plots.  There
     801    are two different syntaxes supported::
     802
     803        sage: plot(exp, (1, 10), scale='semilogy') # log axis on vertical
     804
     805        sage: plot_semilogy(exp, (1, 10)) # same thing
     806
     807        sage: plot_loglog(exp, (1, 10), scale='loglog')   # both axes are log
     808
     809        sage: plot(exp, (1, 10), scale='loglog', base=2) # base of log is 2
     810
     811    We can also change the scale of the axes in the graphics just before
     812    displaying::
     813
     814        sage: G = plot(exp, 1, 10)
     815        sage: G.show(scale=('semilogy', 2))
     816
    782817    The algorithm used to insert extra points is actually pretty
    783818    simple. On the picture drawn by the lines below::
    784    
     819
    785820        sage: p = plot(x^2, (-0.5, 1.4)) + line([(0,0), (1,1)], color='green')
    786821        sage: p += line([(0.5, 0.5), (0.5, 0.5^2)], color='purple')
    787822        sage: p += point(((0, 0), (0.5, 0.5), (0.5, 0.5^2), (1, 1)), color='red', pointsize=20)
     
    13941429        sage: parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green')
    13951430        sage: parametric_plot( vector([t, t+1, t^2]), (t, 0, 1))
    13961431
     1432    Plotting in logarithmic scale is possible with 2D plots. The keyword
     1433    ``aspect_ratio`` will be ignored if the scale is not `loglog` or
     1434    `linear`.::
     1435
     1436        sage: parametric_plot((x, x**2), (x, 1, 10), scale='loglog')
     1437
     1438    We can also change the scale of the axes in the graphics just before
     1439    displaying. In this case, the ``aspect_ratio`` must be specified as
     1440    `automatic` if the ``scale`` is set to `semilogx` or `semilogy`. For
     1441    other values of the ``scale`` parameter, any ``aspect_ratio`` can be
     1442    used, or the keyword need not be provided.::
     1443
     1444        sage: p = parametric_plot((x, x**2), (x, 1, 10))
     1445        sage: p.show(scale='semilogy', aspect_ratio='automatic')
     1446
    13971447    TESTS::
    13981448   
    13991449        sage: parametric_plot((x, t^2), (x, -4, 4))
     
    14401490    if num_vars>num_ranges:
    14411491        raise ValueError, "there are more variables than variable ranges"
    14421492
     1493    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     1494    # Otherwise matplotlib complains.
     1495    scale = kwargs.get('scale', None)
     1496    if isinstance(scale, (list, tuple)):
     1497        scale = scale[0]
     1498    if scale == 'semilogy' or scale == 'semilogx':
     1499        kwargs['aspect_ratio'] = 'automatic'
     1500
    14431501    if num_funcs == 2 and num_ranges == 1:
    14441502        kwargs['parametric'] = True                   
    14451503        return plot(funcs, *args, **kwargs)
     
    15811639
    15821640        sage: list_plot({22: 3365, 27: 3295, 37: 3135, 42: 3020, 47: 2880, 52: 2735, 57: 2550})
    15831641
     1642    Plotting in logarithmic scale is possible for 2D plots.::
     1643
     1644        sage: yl = [2**k for k in range(10)]
     1645        sage: list_plot(yl, scale='semilogy')       # log axis on vertical
     1646
     1647        sage: list_plot(yl, scale='loglog')         # both axes are log
     1648
     1649        sage: list_plot(yl, scale='loglog', base=2) # base of log is 2
     1650
     1651    We can also change the scale of the axes in the graphics just before
     1652    displaying::
     1653
     1654        sage: G = list_plot(yl)
     1655        sage: G.show(scale=('semilogy', 2))
     1656
    15841657    TESTS:
    15851658
    15861659    We check to see that the x/y min/max data are set correctly.
     
    16261699        else:
    16271700            return point(data, **kwargs)
    16281701
     1702#------------------------ Graphs on log scale ---------------------------#
     1703@options(base=10)
     1704def plot_loglog(funcs, *args, **kwds):
     1705    """
     1706    Plot graphics in 'loglog' scale, that is, both the horizontal and the
     1707    vertical axes will be in logarithmic scale.
     1708
     1709    INPUTS:
     1710
     1711    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1712      greater than 1. The base can be also given as a list or tuple
     1713      ``(basex, basey)``.  ``basex`` sets the base of the logarithm along the
     1714      horizontal axis and ``basey`` sets the base along the vertical axis.
     1715
     1716    - ``funcs`` -- any Sage object which is acceptable to the :func:`plot`.
     1717
     1718    For all other inputs, look at the documentation of :func:`plot`.
     1719
     1720    EXAMPLES::
     1721
     1722        sage: plot_loglog(exp, (1,10)) # plot in loglog scale with base 10
     1723
     1724        sage: plot_loglog(exp, (1,10), base=2) # with base 2 on both axes
     1725
     1726        sage: plot_loglog(exp, (1,10), base=(2,3))
     1727
     1728    """
     1729    return plot(funcs, *args, scale='loglog', **kwds)
     1730
     1731@options(base=10)
     1732def plot_semilogx(funcs, *args, **kwds):
     1733    """
     1734    Plot graphics in 'semilogx' scale, that is, the horizontal axis will be
     1735    in logarithmic scale.
     1736
     1737    INPUTS:
     1738
     1739    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1740      greater than 1.
     1741
     1742    - ``funcs`` -- any Sage object which is acceptable to the :func:`plot`.
     1743
     1744    For all other inputs, look at the documentation of :func:`plot`.
     1745
     1746    EXAMPLES::
     1747
     1748        sage: plot_semilogx(exp, (1,10)) # plot in semilogx scale, base 10
     1749
     1750        sage: plot_semilogx(exp, (1,10), base=2) # with base 2
     1751
     1752    """
     1753    return plot(funcs, *args, scale='semilogx', **kwds)
     1754
     1755@options(base=10)
     1756def plot_semilogy(funcs, *args, **kwds):
     1757    """
     1758    Plot graphics in 'semilogy' scale, that is, the vertical axis will be
     1759    in logarithmic scale.
     1760
     1761    INPUTS:
     1762
     1763    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1764      greater than 1.
     1765
     1766    - ``funcs`` -- any Sage object which is acceptable to the :func:`plot`.
     1767
     1768    For all other inputs, look at the documentation of :func:`plot`.
     1769
     1770    EXAMPLES::
     1771
     1772        sage: plot_semilogy(exp, (1,10)) # plot in semilogy scale, base 10
     1773
     1774        sage: plot_semilogy(exp, (1,10), base=2) # with base 2
     1775
     1776    """
     1777    return plot(funcs, *args, scale='semilogy', **kwds)
     1778
     1779@options(base=10)
     1780def list_plot_loglog(data, plotjoined=False, **kwds):
     1781    """
     1782    Plot the `data` in 'loglog' scale, that is, both the horizontal and the
     1783    vertical axes will be in logarithmic scale.
     1784
     1785    INPUTS:
     1786
     1787    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1788      greater than 1. The base can be also given as a list or tuple
     1789      ``(basex, basey)``.  ``basex`` sets the base of the logarithm along the
     1790      horizontal axis and ``basey`` sets the base along the vertical axis.
     1791
     1792    For all other inputs, look at the documentation of :func:`list_plot`.
     1793
     1794    EXAMPLES::
     1795
     1796        sage: yl = [5**k for k in range(10)]; xl = [2**k for k in range(10)]
     1797        sage: list_plot_loglog(zip(xl, yl)) # plot in loglog scale with base 10
     1798
     1799        sage: list_plot_loglog(zip(xl, yl), base=2) # with base 2 on both axes
     1800
     1801        sage: list_plot_loglog(zip(xl, yl), base=(2,5))
     1802
     1803    """
     1804    return list_plot(data, plotjoined=plotjoined, scale='loglog', **kwds)
     1805
     1806@options(base=10)
     1807def list_plot_semilogx(data, plotjoined=False, **kwds):
     1808    """
     1809    Plot `data` in 'semilogx' scale, that is, the horizontal axis will be
     1810    in logarithmic scale.
     1811
     1812    INPUTS:
     1813
     1814    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1815      greater than 1.
     1816
     1817    For all other inputs, look at the documentation of :func:`plot`.
     1818
     1819    EXAMPLES::
     1820
     1821        sage: yl = [5**k for k in range(10)]
     1822        sage: list_plot_semilogx(yl) # plot in semilogx scale, base 10
     1823
     1824        sage: list_plot_semilogx(yl, base=2) # with base 2
     1825
     1826    """
     1827    return list_plot(data, plotjoined=plotjoined, scale='semilogx', **kwds)
     1828
     1829@options(base=10)
     1830def list_plot_semilogy(data, plotjoined=False, **kwds):
     1831    """
     1832    Plot `data` in 'semilogy' scale, that is, the vertical axis will be
     1833    in logarithmic scale.
     1834
     1835    INPUTS:
     1836
     1837    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1838      greater than 1.
     1839
     1840    For all other inputs, look at the documentation of :func:`plot`.
     1841
     1842    EXAMPLES::
     1843
     1844        sage: yl = [5**k for k in range(10)]
     1845        sage: list_plot_semilogy(yl) # plot in semilogy scale, base 10
     1846
     1847        sage: list_plot_semilogy(yl, base=5) # with base 5
     1848
     1849    """
     1850    return list_plot(data, plotjoined=plotjoined, scale='semilogy', **kwds)
     1851
    16291852def to_float_list(v):
    16301853    """
    16311854    Given a list or tuple or iterable v, coerce each element of v to a