Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8bf6705

Browse filesBrowse files
committed
Merge pull request #5587 from mdboom/no-explicit-mathdefault
API: No explicit mathdefault in log formatter
1 parent 27adae6 commit 8bf6705
Copy full SHA for 8bf6705

File tree

Expand file treeCollapse file tree

1 file changed

+23
-10
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-10
lines changed

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+23-10Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@
168168
long = int
169169

170170

171+
def _mathdefault(s):
172+
"""
173+
For backward compatibility, in classic mode we display
174+
sub/superscripted text in a mathdefault block. As of 2.0, the
175+
math font already matches the default font, so we don't need to do
176+
that anymore.
177+
"""
178+
if rcParams['_internal.classic_mode']:
179+
return '\\mathdefault{%s}' % s
180+
else:
181+
return '{%s}' % s
182+
183+
171184
class _DummyAxis(object):
172185
def __init__(self, minpos=0):
173186
self.dataLim = mtransforms.Bbox.unit()
@@ -510,9 +523,8 @@ def get_offset(self):
510523
sciNotStr = '1e%d' % self.orderOfMagnitude
511524
if self._useMathText:
512525
if sciNotStr != '':
513-
sciNotStr = r'\times\mathdefault{%s}' % sciNotStr
514-
s = ''.join(('$', sciNotStr,
515-
r'\mathdefault{', offsetStr, '}$'))
526+
sciNotStr = r'\times%s' % _mathdefault(sciNotStr)
527+
s = ''.join(('$', sciNotStr, _mathdefault(offsetStr), '$'))
516528
elif self._usetex:
517529
if sciNotStr != '':
518530
sciNotStr = r'\times%s' % sciNotStr
@@ -613,7 +625,7 @@ def _set_format(self, vmin, vmax):
613625
if self._usetex:
614626
self.format = '$%s$' % self.format
615627
elif self._useMathText:
616-
self.format = '$\mathdefault{%s}$' % self.format
628+
self.format = '$%s$' % _mathdefault(self.format)
617629

618630
def pprint_val(self, x):
619631
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
@@ -790,7 +802,7 @@ def __call__(self, x, pos=None):
790802
if usetex:
791803
return '$0$'
792804
else:
793-
return '$\mathdefault{0}$'
805+
return '$%s$' % _mathdefault('0')
794806

795807
fx = math.log(abs(x)) / math.log(b)
796808
is_decade = is_close_to_int(fx)
@@ -810,17 +822,18 @@ def __call__(self, x, pos=None):
810822
return (r'$%s%s^{%.2f}$') % \
811823
(sign_string, base, fx)
812824
else:
813-
return ('$\mathdefault{%s%s^{%.2f}}$') % \
814-
(sign_string, base, fx)
825+
return ('$%s$' % _mathdefault(
826+
'%s%s^{%.2f}' %
827+
(sign_string, base, fx)))
815828
else:
816829
if usetex:
817830
return (r'$%s%s^{%d}$') % (sign_string,
818831
base,
819832
nearest_long(fx))
820833
else:
821-
return (r'$\mathdefault{%s%s^{%d}}$') % (sign_string,
822-
base,
823-
nearest_long(fx))
834+
return ('$%s$' % _mathdefault(
835+
'%s%s^{%d}' %
836+
(sign_string, base, nearest_long(fx))))
824837

825838

826839
class LogitFormatter(Formatter):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.