Ticket #4529: trac_4529-single-tick.patch

File trac_4529-single-tick.patch, 4.5 KB (added by kcrisman, 9 years ago)
  • sage/plot/graphics.py

    # HG changeset patch
    # User Punarbasu Purkayastha <ppurka@gmail.com>
    # Date 1338109823 -28800
    # Node ID 56bf4a37f1bb22520aae1d801c500416667e4ac9
    # Parent  50485c4d4dd2d50839e508b720ba0121053e528f
    check for the presence of single tick
      - this is not robust enough in all cases for the log scale
      - including this patch will mean that most graphics such as arc, disk, etc
        which "just work" with log scale, will stop working.
    
    diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
    a b  
    14341434
    14351435            sage: G.show(scale=('loglog', 2, 3)) # x in base 2, y in base 3
    14361436
    1437         The base need not be an integer.::
    1438 
    1439             sage: G.show(scale='semilogy', base=float(e)) # base is e
     1437        The base need not be an integer, though it does have to be made
     1438        a float.  Also, currently the formatting is wrong for non-integer bases,
     1439        such as in this example::
     1440
     1441            sage: G.show(scale='semilogx', base=float(e)) # base is e
    14401442
    14411443        Logarithmic scale can be used for various kinds of plots. Here are
    14421444        some examples.::
     
    14471449            sage: G = parametric_plot((x, x**2), (x, 1, 10))
    14481450            sage: G.show(scale='loglog')
    14491451
     1452            sage: disk((5,5), 4, (0, 3*pi/2)).show(scale='loglog',base=2)
     1453
     1454            sage: x, y = var('x, y')
     1455            sage: G =  plot_vector_field((2^x,y^2),(x,1,10),(y,1,100))
     1456            sage: G.show(scale='semilogx',base=2)
     1457
     1458        But be sure to only plot things that will have a wide enough range
     1459        for the logarithmic scale to be interpretable::
     1460
    14501461            sage: G = arc((2,3), 2, 1, angle=pi/2, sector=(0,pi/2))
    14511462            sage: G.show(scale=('loglog', 2))
    1452 
    1453             sage: disk((0.1,0.1), 1, (pi/3, pi/2)).show(scale='loglog')
    1454 
    1455             sage: polygon([(1,1), (10,10), (10,1)]).show(scale='loglog')
    1456 
    1457             sage: x, y = var('x, y')
    1458             sage: G =  plot_vector_field((sin(x),cos(y)),(x,0.1,3),(y,0.1,3))
    1459             sage: G.show(scale='loglog')
     1463            Traceback (most recent call last):
     1464            ...
     1465            ValueError: Either expand the range of the dependent variable to allow two different integer powers of your `base`, or change your `base` to a smaller number.
    14601466
    14611467        Add grid lines at the major ticks of the axes.
    14621468
     
    16291635
    16301636            sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=[None,pi]) # Not so nice-looking
    16311637
     1638        When using logarithmic scale along the axis, make sure to have
     1639        enough room for two ticks so that the user can tell what the scale
     1640        is. This can be effected by increasing the range of the independent
     1641        variable, or by changing the ``base``.::
     1642
     1643            sage: p = list_plot(range(1, 10), plotjoined=True)
     1644            sage: p.show(scale='loglog')
     1645            Traceback (most recent call last):
     1646            ...
     1647            ValueError: Either expand the range of the dependent variable to allow two different integer powers of your `base`, or change your `base` to a smaller number.
     1648            sage: p.show(scale='loglog', base=8) # this works.
     1649
    16321650        """
    16331651
    16341652        # This option should not be passed on to save().
     
    18901908        subplot.xaxis.set_major_formatter(x_formatter)
    18911909        subplot.yaxis.set_major_formatter(y_formatter)
    18921910
     1911        # Check for whether there will be too few ticks in the log scale case
     1912        # If part of the data is nonpositive, we assume there are enough ticks
     1913        if scale[0] == 'log' and xmin > 0:
     1914            import math
     1915            base0 = base[0]
     1916            if (math.floor(math.log(xmax)/math.log(base0)) -
     1917                    math.ceil(math.log(xmin)/math.log(base0)) < 1):
     1918                raise ValueError('Either expand the range of the independent '
     1919                'variable to allow two different integer powers of your `base`, '
     1920                'or change your `base` to a smaller number.')
     1921        if scale[1] == 'log' and ymin > 0:
     1922            import math
     1923            base1 = base[1]
     1924            if (math.floor(math.log(ymax)/math.log(base1)) -
     1925                    math.ceil(math.log(ymin)/math.log(base1)) < 1):
     1926                raise ValueError('Either expand the range of the dependent '
     1927                'variable to allow two different integer powers of your `base`, '
     1928                'or change your `base` to a smaller number.')
     1929
    18931930        return (subplot, x_locator, y_locator, x_formatter, y_formatter)
    18941931
    18951932    def matplotlib(self, filename=None,