# 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
|
|
1434 | 1434 | |
1435 | 1435 | sage: G.show(scale=('loglog', 2, 3)) # x in base 2, y in base 3 |
1436 | 1436 | |
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 |
1440 | 1442 | |
1441 | 1443 | Logarithmic scale can be used for various kinds of plots. Here are |
1442 | 1444 | some examples.:: |
… |
… |
|
1447 | 1449 | sage: G = parametric_plot((x, x**2), (x, 1, 10)) |
1448 | 1450 | sage: G.show(scale='loglog') |
1449 | 1451 | |
| 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 | |
1450 | 1461 | sage: G = arc((2,3), 2, 1, angle=pi/2, sector=(0,pi/2)) |
1451 | 1462 | 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. |
1460 | 1466 | |
1461 | 1467 | Add grid lines at the major ticks of the axes. |
1462 | 1468 | |
… |
… |
|
1629 | 1635 | |
1630 | 1636 | sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=[None,pi]) # Not so nice-looking |
1631 | 1637 | |
| 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 | |
1632 | 1650 | """ |
1633 | 1651 | |
1634 | 1652 | # This option should not be passed on to save(). |
… |
… |
|
1890 | 1908 | subplot.xaxis.set_major_formatter(x_formatter) |
1891 | 1909 | subplot.yaxis.set_major_formatter(y_formatter) |
1892 | 1910 | |
| 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 | |
1893 | 1930 | return (subplot, x_locator, y_locator, x_formatter, y_formatter) |
1894 | 1931 | |
1895 | 1932 | def matplotlib(self, filename=None, |