Ticket #4529: trac_4529docsandfuncs.2.patch
File trac_4529docsandfuncs.2.patch, 12.6 KB (added by , 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 1 1 from graphics import show_default, Graphics, is_Graphics 2 2 from plot import plot, graphics_array, list_plot, parametric_plot, polar_plot 3 from plot import plot_loglog, plot_semilogx, plot_semilogy 4 from plot import list_plot_loglog, list_plot_semilogx, list_plot_semilogy 3 5 from line import line, line2d 4 6 from arrow import arrow, arrow2d 5 7 from 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 526 526 527 527  ``legend_label``  the label for this item in the legend 528 528 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 529 547 EXAMPLES: 530 548 531 549 A simple circle with a radius of 2. Note that … … 605 623 606 624 sage: implicit_plot(lambda x,y: x^2+y^22, (x,3,3), (y,3,3), fill=True, plot_points=500) # long time 607 625 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 608 630 TESTS:: 609 631 610 632 sage: f(x,y) = x^2 + y^2  2 … … 683 705 684 706  ``legend_label``  the label for this item in the legend 685 707 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 686 726 687 727 EXAMPLES: 688 728 … … 742 782 743 783 sage: region_plot(s>0,(s,2,2),(t,2,2)) 744 784 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 745 789 """ 746 790 747 791 from sage.plot.all import Graphics 
sage/plot/plot.py
diff git a/sage/plot/plot.py b/sage/plot/plot.py
a b 591 591 documentation further below for more information, starting at "the 592 592 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 594 612  ``xmin``  starting x value 595 613 596 614  ``xmax``  ending x value … … 779 797 780 798 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 782 817 The algorithm used to insert extra points is actually pretty 783 818 simple. On the picture drawn by the lines below:: 784 819 … … 1360 1395 sage: parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green') 1361 1396 sage: parametric_plot( vector([t, t+1, t^2]), (t, 0, 1)) 1362 1397 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 1363 1413 TESTS:: 1364 1414 1365 1415 sage: parametric_plot((x, t^2), (x, 4, 4)) … … 1406 1456 if num_vars>num_ranges: 1407 1457 raise ValueError, "there are more variables than variable ranges" 1408 1458 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 1409 1467 if num_funcs == 2 and num_ranges == 1: 1410 1468 kwargs['parametric'] = True 1411 1469 return plot(funcs, *args, **kwargs) … … 1547 1605 1548 1606 sage: list_plot({22: 3365, 27: 3295, 37: 3135, 42: 3020, 47: 2880, 52: 2735, 57: 2550}) 1549 1607 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 1550 1623 TESTS: 1551 1624 1552 1625 We check to see that the x/y min/max data are set correctly. … … 1592 1665 else: 1593 1666 return point(data, **kwargs) 1594 1667 1668 # Graphs on log scale # 1669 @options(base=10) 1670 def 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) 1698 def 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) 1722 def 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) 1746 def 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) 1773 def 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) 1796 def 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 1595 1818 def to_float_list(v): 1596 1819 """ 1597 1820 Given a list or tuple or iterable v, coerce each element of v to a