Skip to content

Commit bd54629

Browse files
author
Matthias Koeppe
committed
Merge #34693
2 parents 0ecabe5 + 6458968 commit bd54629

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/sage/plot/graphics.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ def _matplotlib_tick_formatter(self, subplot, base=(10, 10),
23662366
elif x_locator == []:
23672367
x_locator = NullLocator()
23682368
elif isinstance(x_locator, list):
2369-
x_locator = FixedLocator(x_locator)
2369+
x_locator = FixedLocator([float(x) for x in x_locator])
23702370
else: # x_locator is a number which can be made a float
23712371
from sage.functions.other import ceil, floor
23722372
if floor(xmax / x_locator) - ceil(xmin / x_locator) > 1:
@@ -2387,7 +2387,7 @@ def _matplotlib_tick_formatter(self, subplot, base=(10, 10),
23872387
elif y_locator == []:
23882388
y_locator = NullLocator()
23892389
elif isinstance(y_locator, list):
2390-
y_locator = FixedLocator(y_locator)
2390+
y_locator = FixedLocator([float(y) for y in y_locator])
23912391
else: # y_locator is a number which can be made a float
23922392
from sage.functions.other import ceil, floor
23932393
if floor(ymax / y_locator) - ceil(ymin / y_locator) > 1:
@@ -2419,7 +2419,11 @@ def _matplotlib_tick_formatter(self, subplot, base=(10, 10),
24192419
LogFormatterMathtext(base=base[0])(n, pos).replace(
24202420
"\\mathdefault", ""))
24212421
else:
2422-
x_formatter = FuncFormatter(lambda n, pos: '$%s$' % latex(n))
2422+
# circumvent the problem of symbolic tick values (trac #34693)
2423+
if isinstance(x_locator, FixedLocator):
2424+
x_formatter = FixedFormatter(['$%s$' % latex(n) for n in ticks[0]])
2425+
else:
2426+
x_formatter = FuncFormatter(lambda n, pos: '$%s$' % latex(n))
24232427
elif isinstance(x_formatter, (list, tuple)):
24242428
if (not isinstance(ticks[0], (list, tuple)) or
24252429
len(ticks[0]) != len(x_formatter)):
@@ -2444,7 +2448,11 @@ def _matplotlib_tick_formatter(self, subplot, base=(10, 10),
24442448
LogFormatterMathtext(base=base[1])(n, pos).replace(
24452449
"\\mathdefault", ""))
24462450
else:
2447-
y_formatter = FuncFormatter(lambda n, pos: '$%s$' % latex(n))
2451+
# circumvent the problem of symbolic tick values (trac #34693)
2452+
if isinstance(y_locator, FixedLocator):
2453+
y_formatter = FixedFormatter(['$%s$' % latex(n) for n in ticks[1]])
2454+
else:
2455+
y_formatter = FuncFormatter(lambda n, pos: '$%s$' % latex(n))
24482456
elif isinstance(y_formatter, (list, tuple)):
24492457
if (not isinstance(ticks[1], (list, tuple)) or
24502458
len(ticks[1]) != len(y_formatter)):

src/sage/plot/plot.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,10 +1741,15 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1)
17411741
17421742
::
17431743
1744-
sage: plot(2*x+1,(x,0,5),ticks=[[0,1,e,pi,sqrt(20)],2],tick_formatter="latex") # not tested (broken with matplotlib 3.6)
1744+
sage: plot(2*x + 1,(x, 0, 5), ticks=[[0, 1, e, pi, sqrt(20)], [1, 3, 2*e + 1, 2*pi + 1, 2*sqrt(20) + 1]], tick_formatter="latex")
17451745
Graphics object consisting of 1 graphics primitive
17461746
1747-
This is particularly useful when setting custom ticks in multiples of `pi`.
1747+
.. PLOT::
1748+
1749+
g = plot(2*x + 1,(x, 0, 5), ticks=[[0, 1, e, pi, sqrt(20)], [1, 3, 2*e + 1, 2*pi + 1, 2*sqrt(20) + 1]], tick_formatter="latex")
1750+
sphinx_plot(g)
1751+
1752+
This is particularly useful when setting custom ticks in multiples of `\pi`.
17481753
17491754
::
17501755

0 commit comments

Comments
 (0)