Ticket #4529: trac_4529-docs-and-funcs.2.patch

File trac_4529-docs-and-funcs.2.patch, 12.6 KB (added by ppurka, 9 years ago)
  • sage/plot/all.py

    # HG changeset patch
    # User Punarbasu Purkayastha <ppurka@gmail.com>
    # Date 1337533730 -28800
    # Node ID 20426b54923774fb9a03eff99b0d459591fadcec
    # Parent  ff43705445eef10e6845688d77a3fcd97d3f2b1e
     - 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  
    526526
    527527    - ``legend_label`` -- the label for this item in the legend
    528528
     529    - ``base`` - (default: 10) the base of the logarithm if
     530      a logarithmic scale is set. This must be greater than 1. The base
     531      can be also given as a list or tuple ``(basex, basey)``.
     532      ``basex`` sets the base of the logarithm along the horizontal
     533      axis and ``basey`` sets the base along the vertical axis.
     534
     535    - ``scale`` -- (default: `linear`) string. The scale of the axes.
     536      Possible values are `linear`, `loglog`, `semilogx`, `semilogy`.
     537
     538      The scale can be also be given as single argument that is a list
     539      or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
     540
     541      The `loglog` scale sets both the horizontal and vertical axes to
     542      logarithmic scale. The `semilogx` scale sets the horizontal axis
     543      to logarithmic scale. The `semilogy` scale sets the vertical axis
     544      to logarithmic scale. The `linear` scale is the default value
     545      when :class:`Graphics` is initialized.
     546
    529547    EXAMPLES:
    530548
    531549    A simple circle with a radius of 2. Note that
     
    605623
    606624        sage: implicit_plot(lambda x,y: x^2+y^2-2, (x,-3,3), (y,-3,3), fill=True, plot_points=500) # long time
    607625
     626    An example of an implicit plot on 'loglog' scale::
     627
     628        sage: implicit_plot(x^2+y^2 == 200, (x,1,200), (y,1,200), scale='loglog')
     629
    608630    TESTS::
    609631
    610632        sage: f(x,y) = x^2 + y^2 - 2
     
    683705
    684706    - ``legend_label`` -- the label for this item in the legend
    685707
     708    - ``base`` - (default: 10) the base of the logarithm if
     709      a logarithmic scale is set. This must be greater than 1. The base
     710      can be also given as a list or tuple ``(basex, basey)``.
     711      ``basex`` sets the base of the logarithm along the horizontal
     712      axis and ``basey`` sets the base along the vertical axis.
     713
     714    - ``scale`` -- (default: `linear`) string. The scale of the axes.
     715      Possible values are `linear`, `loglog`, `semilogx`, `semilogy`.
     716
     717      The scale can be also be given as single argument that is a list
     718      or tuple ``(scale, base)`` or ``(scale, basex, basey)``.
     719
     720      The `loglog` scale sets both the horizontal and vertical axes to
     721      logarithmic scale. The `semilogx` scale sets the horizontal axis
     722      to logarithmic scale. The `semilogy` scale sets the vertical axis
     723      to logarithmic scale. The `linear` scale is the default value
     724      when :class:`Graphics` is initialized.
     725
    686726
    687727    EXAMPLES:
    688728
     
    742782
    743783        sage: region_plot(s>0,(s,-2,2),(t,-2,2))
    744784
     785    An example of a region plot in 'loglog' scale::
     786
     787        sage: region_plot(x^2+y^2<100, (x,1,10), (y,1,10), scale='loglog')
     788
    745789    """
    746790
    747791    from sage.plot.all import Graphics
  • sage/plot/plot.py

    diff --git a/sage/plot/plot.py b/sage/plot/plot.py
    a b  
    591591      documentation further below for more information, starting at "the
    592592      algorithm used to insert".
    593593
     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
     
    779797
    780798        sage: plot(sin(1/x), (-1, 1))
    781799
     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::
    784819
     
    13601395        sage: parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green')
    13611396        sage: parametric_plot( vector([t, t+1, t^2]), (t, 0, 1))
    13621397
     1398    Plotting in logarithmic scale is possible with 2D plots. The keyword
     1399    ``aspect_ratio`` will be ignored if the scale is not `loglog` or
     1400    `linear`.::
     1401
     1402        sage: parametric_plot((x, x**2), (x, 1, 10), scale='loglog')
     1403
     1404    We can also change the scale of the axes in the graphics just before
     1405    displaying. In this case, the ``aspect_ratio`` must be specified as
     1406    `automatic` if the ``scale`` is set to `semilogx` or `semilogy`. For
     1407    other values of the ``scale`` parameter, any ``aspect_ratio`` can be
     1408    used, or the keyword need not be provided.::
     1409
     1410        sage: p = parametric_plot((x, x**2), (x, 1, 10))
     1411        sage: p.show(scale='semilogy', aspect_ratio='automatic')
     1412
    13631413    TESTS::
    13641414
    13651415        sage: parametric_plot((x, t^2), (x, -4, 4))
     
    14061456    if num_vars>num_ranges:
    14071457        raise ValueError, "there are more variables than variable ranges"
    14081458
     1459    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
     1460    # Otherwise matplotlib complains.
     1461    scale = kwargs.get('scale', None)
     1462    if isinstance(scale, (list, tuple)):
     1463        scale = scale[0]
     1464    if scale == 'semilogy' or scale == 'semilogx':
     1465        kwargs['aspect_ratio'] = 'automatic'
     1466
    14091467    if num_funcs == 2 and num_ranges == 1:
    14101468        kwargs['parametric'] = True
    14111469        return plot(funcs, *args, **kwargs)
     
    15471605
    15481606        sage: list_plot({22: 3365, 27: 3295, 37: 3135, 42: 3020, 47: 2880, 52: 2735, 57: 2550})
    15491607
     1608    Plotting in logarithmic scale is possible for 2D plots.::
     1609
     1610        sage: yl = [2**k for k in range(10)]
     1611        sage: list_plot(yl, scale='semilogy')       # log axis on vertical
     1612
     1613        sage: list_plot(yl, scale='loglog')         # both axes are log
     1614
     1615        sage: list_plot(yl, scale='loglog', base=2) # base of log is 2
     1616
     1617    We can also change the scale of the axes in the graphics just before
     1618    displaying::
     1619
     1620        sage: G = list_plot(yl)
     1621        sage: G.show(scale=('semilogy', 2))
     1622
    15501623    TESTS:
    15511624
    15521625    We check to see that the x/y min/max data are set correctly.
     
    15921665        else:
    15931666            return point(data, **kwargs)
    15941667
     1668#------------------------ Graphs on log scale ---------------------------#
     1669@options(base=10)
     1670def plot_loglog(funcs, *args, **kwds):
     1671    """
     1672    Plot graphics in 'loglog' scale, that is, both the horizontal and the
     1673    vertical axes will be in logarithmic scale.
     1674
     1675    INPUTS:
     1676
     1677    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1678      greater than 1. The base can be also given as a list or tuple
     1679      ``(basex, basey)``.  ``basex`` sets the base of the logarithm along the
     1680      horizontal axis and ``basey`` sets the base along the vertical axis.
     1681
     1682    - ``funcs`` -- any Sage object which is acceptable to the :func:`plot`.
     1683
     1684    For all other inputs, look at the documentation of :func:`plot`.
     1685
     1686    EXAMPLES::
     1687
     1688        sage: plot_loglog(exp, (1,10)) # plot in loglog scale with base 10
     1689
     1690        sage: plot_loglog(exp, (1,10), base=2) # with base 2 on both axes
     1691
     1692        sage: plot_loglog(exp, (1,10), base=(2,3))
     1693
     1694    """
     1695    return plot(funcs, *args, scale='loglog', **kwds)
     1696
     1697@options(base=10)
     1698def plot_semilogx(funcs, *args, **kwds):
     1699    """
     1700    Plot graphics in 'semilogx' scale, that is, the horizontal axis will be
     1701    in logarithmic scale.
     1702
     1703    INPUTS:
     1704
     1705    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1706      greater than 1.
     1707
     1708    - ``funcs`` -- any Sage object which is acceptable to the :func:`plot`.
     1709
     1710    For all other inputs, look at the documentation of :func:`plot`.
     1711
     1712    EXAMPLES::
     1713
     1714        sage: plot_semilogx(exp, (1,10)) # plot in semilogx scale, base 10
     1715
     1716        sage: plot_semilogx(exp, (1,10), base=2) # with base 2
     1717
     1718    """
     1719    return plot(funcs, *args, scale='semilogx', **kwds)
     1720
     1721@options(base=10)
     1722def plot_semilogy(funcs, *args, **kwds):
     1723    """
     1724    Plot graphics in 'semilogy' scale, that is, the vertical axis will be
     1725    in logarithmic scale.
     1726
     1727    INPUTS:
     1728
     1729    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1730      greater than 1.
     1731
     1732    - ``funcs`` -- any Sage object which is acceptable to the :func:`plot`.
     1733
     1734    For all other inputs, look at the documentation of :func:`plot`.
     1735
     1736    EXAMPLES::
     1737
     1738        sage: plot_semilogy(exp, (1,10)) # plot in semilogy scale, base 10
     1739
     1740        sage: plot_semilogy(exp, (1,10), base=2) # with base 2
     1741
     1742    """
     1743    return plot(funcs, *args, scale='semilogy', **kwds)
     1744
     1745@options(base=10)
     1746def list_plot_loglog(data, plotjoined=False, **kwds):
     1747    """
     1748    Plot the `data` in 'loglog' scale, that is, both the horizontal and the
     1749    vertical axes will be in logarithmic scale.
     1750
     1751    INPUTS:
     1752
     1753    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1754      greater than 1. The base can be also given as a list or tuple
     1755      ``(basex, basey)``.  ``basex`` sets the base of the logarithm along the
     1756      horizontal axis and ``basey`` sets the base along the vertical axis.
     1757
     1758    For all other inputs, look at the documentation of :func:`list_plot`.
     1759
     1760    EXAMPLES::
     1761
     1762        sage: yl = [5**k for k in range(10)]; xl = [2**k for k in range(10)]
     1763        sage: list_plot_loglog(zip(xl, yl)) # plot in loglog scale with base 10
     1764
     1765        sage: list_plot_loglog(zip(xl, yl), base=2) # with base 2 on both axes
     1766
     1767        sage: list_plot_loglog(zip(xl, yl), base=(2,5))
     1768
     1769    """
     1770    return list_plot(data, plotjoined=plotjoined, scale='loglog', **kwds)
     1771
     1772@options(base=10)
     1773def list_plot_semilogx(data, plotjoined=False, **kwds):
     1774    """
     1775    Plot `data` in 'semilogx' scale, that is, the horizontal axis will be
     1776    in logarithmic scale.
     1777
     1778    INPUTS:
     1779
     1780    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1781      greater than 1.
     1782
     1783    For all other inputs, look at the documentation of :func:`plot`.
     1784
     1785    EXAMPLES::
     1786
     1787        sage: yl = [5**k for k in range(10)]
     1788        sage: list_plot_semilogx(yl) # plot in semilogx scale, base 10
     1789
     1790        sage: list_plot_semilogx(yl, base=2) # with base 2
     1791
     1792    """
     1793    return list_plot(data, plotjoined=plotjoined, scale='semilogx', **kwds)
     1794
     1795@options(base=10)
     1796def list_plot_semilogy(data, plotjoined=False, **kwds):
     1797    """
     1798    Plot `data` in 'semilogy' scale, that is, the vertical axis will be
     1799    in logarithmic scale.
     1800
     1801    INPUTS:
     1802
     1803    - ``base`` -- (default: 10) the base of the logarithm. This must be
     1804      greater than 1.
     1805
     1806    For all other inputs, look at the documentation of :func:`plot`.
     1807
     1808    EXAMPLES::
     1809
     1810        sage: yl = [5**k for k in range(10)]
     1811        sage: list_plot_semilogy(yl) # plot in semilogy scale, base 10
     1812
     1813        sage: list_plot_semilogy(yl, base=5) # with base 5
     1814
     1815    """
     1816    return list_plot(data, plotjoined=plotjoined, scale='semilogy', **kwds)
     1817
    15951818def to_float_list(v):
    15961819    """
    15971820    Given a list or tuple or iterable v, coerce each element of v to a