Ticket #4529: trac_4529-check_for_single_tick.patch

File trac_4529-check_for_single_tick.patch, 3.0 KB (added by ppurka, 9 years ago)

apply to devel/sage

  • sage/plot/graphics.py

    # HG changeset patch
    # User Punarbasu Purkayastha <ppurka@gmail.com>
    # Date 1338109823 -28800
    # Node ID f2655af5d767771645fcdd71b866ddc1a862ebbf
    # Parent  459c5094f70bf6f10a64dc60349943e5abdf36f6
    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  
    14461446            sage: G = parametric_plot((x, x**2), (x, 1, 10))
    14471447            sage: G.show(scale='loglog')
    14481448
    1449             sage: G = arc((2,3), 2, 1, angle=pi/2, sector=(0,pi/2))
    1450             sage: G.show(scale=('loglog', 2))
    1451 
    1452             sage: disk((0.1,0.1), 1, (pi/3, pi/2)).show(scale='loglog')
    1453 
    1454             sage: polygon([(1,1), (10,10), (10,1)]).show(scale='loglog')
    1455 
    1456             sage: x, y = var('x, y')
    1457             sage: G =  plot_vector_field((sin(x),cos(y)),(x,0.1,3),(y,0.1,3))
    1458             sage: G.show(scale='loglog')
    1459 
    14601449        Add grid lines at the major ticks of the axes.
    14611450
    14621451        ::
     
    16281617
    16291618            sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=[None,pi]) # Not so nice-looking
    16301619
     1620        When using logarithmic scale along the axis, make sure to have
     1621        enough room for two ticks so that the user can tell what the scale
     1622        is. This can be effected by increasing the range of the independent
     1623        variable, or by changing the ``base``.::
     1624
     1625            sage: p = list_plot(range(1, 10), plotjoined=True)
     1626            sage: p.show(scale='loglog')
     1627            Traceback (most recent call last):
     1628            ...
     1629            ValueError: Either expand the range of the independent variable to allow two multiples of the tick locator (option `ticks`), or change your `base` to a smaller number.
     1630            sage: p.show(scale='loglog', base=8) # this works.
     1631
    16311632        """
    16321633
    16331634        # This option should not be passed on to save().
     
    18891890        subplot.xaxis.set_major_formatter(x_formatter)
    18901891        subplot.yaxis.set_major_formatter(y_formatter)
    18911892
     1893        # Only way to reasonably check for too few ticks on log scale seems
     1894        # to be to first set the ticks and then raise an error.
     1895        if scale[0] == 'log' and len(subplot.xaxis.get_ticklocs()) <= 2:
     1896            raise ValueError('Either expand the range of the independent '
     1897            'variable to allow two multiples of the tick locator (option '
     1898            '`ticks`), or change your `base` to a smaller number.')
     1899        if scale[1] == 'log' and len(subplot.yaxis.get_ticklocs()) <= 2:
     1900            raise ValueError('Either expand the range of the dependent '
     1901            'variable to allow two multiples of the tick locator (option '
     1902            '`ticks`), or change your `base` to a smaller number.')
     1903
    18921904        return (subplot, x_locator, y_locator, x_formatter, y_formatter)
    18931905
    18941906    def matplotlib(self, filename=None,