Ticket #1431: formatter.patch

File formatter.patch, 5.6 KB (added by jason, 12 years ago)
  • sage/plot/plot.py

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1257984906 21600
    # Node ID 8698a2d788412b0b95492f7ab546f083eeb6495b
    # Parent  cbe518ff1fdae1a2157d63d12b3105709ce00ecc
    [mq]: formatter.patch
    
    diff -r cbe518ff1fda -r 8698a2d78841 sage/plot/plot.py
    a b  
    11791179                        fontsize=None, aspect_ratio=None,
    11801180                        gridlines=None, gridlinesstyle=None,
    11811181                        vgridlinesstyle=None, hgridlinesstyle=None,transparent=False,
    1182                         axes_pad=.02)
     1182                        axes_pad=.02, tick_locator=None, tick_formatter=None)
    11831183
    11841184    def show(self, **kwds):
    11851185        """
     
    12541254          etc.  To get axes that are exactly the specified limits, set
    12551255          ``axes_pad`` to zero.
    12561256
     1257        - ``tick_locator`` - A matplotlib locator for the major ticks.
     1258          If this is a locator, then it is the locator for the
     1259          horizontal axis.  It can also be a list of two locators, one
     1260          for the horizontal axis and one for the vertical axis.  A
     1261          value of None means use the default locator (so a value of
     1262          [None, my_locator] uses my_locator for the vertical axis and
     1263          the default for the horizontal axis).
     1264
     1265        - ``tick_formatter`` - A matplotlib formatter for the major
     1266          ticks.  If this is a formatter, then it is the formatter for
     1267          the horizontal axis.  It can also be a list of two
     1268          formatters, one for the horizontal axis and one for the
     1269          vertical axis.  A value of None means use the default
     1270          formatter (so a value of [None, my_formatter] uses
     1271          my_formatter for the vertical axis and the default for the
     1272          horizontal axis).
     1273
     1274
    12571275        EXAMPLES::
    12581276       
    12591277            sage: c = circle((1,1), 1, color='red')
     
    15611579              axes=None, axes_labels=None, fontsize=None,
    15621580             frame=False, verify=True, aspect_ratio = None,
    15631581             gridlines=None, gridlinesstyle=None,
    1564              vgridlinesstyle=None, hgridlinesstyle=None,axes_pad=0.02):
     1582             vgridlinesstyle=None, hgridlinesstyle=None,axes_pad=0.02,
     1583             tick_formatter=None, tick_locator=None):
    15651584        r"""
    15661585        Return a matplotlib figure object representing the graphic
    15671586
     
    15841603        :meth:`show` method (this function accepts all except the
    15851604        transparent argument).
    15861605        """
     1606
     1607        if not isinstance(tick_locator, (list, tuple)):
     1608            tick_locator = (tick_locator, None)
     1609
     1610        if not isinstance(tick_formatter, (list, tuple)):
     1611            tick_formatter = (tick_formatter, None)
     1612           
    15871613        self.set_axes_range(xmin, xmax, ymin, ymax)
    15881614        d = self.get_axes_range()
    15891615        xmin = d['xmin']
     
    16541680            # For now, set the formatter to the old one, since that is
    16551681            # sort of what we are used to.  We should eventually look at
    16561682            # the default one to see if we like it better.
     1683
    16571684            from matplotlib.ticker import OldScalarFormatter, MaxNLocator
    1658             subplot.xaxis.set_major_locator(MaxNLocator(nbins=9))
    1659             subplot.yaxis.set_major_locator(MaxNLocator(nbins=9))
    1660             subplot.xaxis.set_major_formatter(OldScalarFormatter())
    1661             subplot.yaxis.set_major_formatter(OldScalarFormatter())
     1685            x_locator, y_locator = tick_locator
     1686            if x_locator is None:
     1687                x_locator = MaxNLocator(nbins=9)
     1688            if y_locator is None:
     1689                y_locator = MaxNLocator(nbins=9)
     1690
     1691            x_formatter, y_formatter = tick_formatter
     1692            if x_formatter is None:
     1693                x_formatter = OldScalarFormatter()
     1694            if y_formatter is None:
     1695                y_formatter = OldScalarFormatter()
     1696           
     1697            subplot.xaxis.set_major_locator(x_locator)
     1698            subplot.yaxis.set_major_locator(y_locator)
     1699            subplot.xaxis.set_major_formatter(x_formatter)
     1700            subplot.yaxis.set_major_formatter(y_formatter)
    16621701           
    16631702            subplot.set_frame_on(True)
    16641703            if axes:
     
    17151754            # For now, set the formatter to the old one, since that is
    17161755            # sort of what we are used to.  We should eventually look at
    17171756            # the default one to see if we like it better.
     1757           
    17181758            from matplotlib.ticker import OldScalarFormatter, MaxNLocator
    1719             subplot.xaxis.set_major_locator(MaxNLocator(nbins=10,steps=[1,2,5,10]))
    1720             subplot.yaxis.set_major_locator(MaxNLocator(nbins=10,steps=[1,2,5,10]))
    1721             subplot.xaxis.set_major_formatter(OldScalarFormatter())
    1722             subplot.yaxis.set_major_formatter(OldScalarFormatter())
     1759            x_locator, y_locator = tick_locator
     1760            if x_locator is None:
     1761                x_locator = MaxNLocator(nbins=9, steps=[1,2,5,10])
     1762            if y_locator is None:
     1763                y_locator = MaxNLocator(nbins=9, steps=[1,2,5,10])
    17231764
     1765            x_formatter, y_formatter = tick_formatter
     1766            if x_formatter is None:
     1767                x_formatter = OldScalarFormatter()
     1768            if y_formatter is None:
     1769                y_formatter = OldScalarFormatter()
     1770           
     1771            subplot.xaxis.set_major_locator(x_locator)
     1772            subplot.yaxis.set_major_locator(y_locator)
     1773            subplot.xaxis.set_major_formatter(x_formatter)
     1774            subplot.yaxis.set_major_formatter(y_formatter)
    17241775
    17251776            # Make ticklines go on both sides of the axes
    17261777            #             if xmiddle: