Skip to content

Commit

Permalink
Fix matplotlib#5542: Don't use mathdefault anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Nov 25, 2015
1 parent 208f306 commit 34cf792
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions lib/matplotlib/ticker.py
Expand Up @@ -168,6 +168,19 @@
long = int


def _mathdefault(s):
"""
For backward compatibility, in classic mode we display
sub/superscripted text in a mathdefault block. As of 2.0, the
math font already matches the default font, so we don't need to do
that anymore.
"""
if rcParams['_internal.classic_mode']:
return '\\mathdefault{%s}' % s
else:
return '{%s}' % s


class _DummyAxis(object):
def __init__(self, minpos=0):
self.dataLim = mtransforms.Bbox.unit()
Expand Down Expand Up @@ -510,9 +523,8 @@ def get_offset(self):
sciNotStr = '1e%d' % self.orderOfMagnitude
if self._useMathText:
if sciNotStr != '':
sciNotStr = r'\times\mathdefault{%s}' % sciNotStr
s = ''.join(('$', sciNotStr,
r'\mathdefault{', offsetStr, '}$'))
sciNotStr = r'\times%s' % _mathdefault(sciNotStr)
s = ''.join(('$', sciNotStr, _mathdefault(offsetStr)))
elif self._usetex:
if sciNotStr != '':
sciNotStr = r'\times%s' % sciNotStr
Expand Down Expand Up @@ -613,7 +625,7 @@ def _set_format(self, vmin, vmax):
if self._usetex:
self.format = '$%s$' % self.format
elif self._useMathText:
self.format = '$\mathdefault{%s}$' % self.format
self.format = '$%s$' % _mathdefault(self.format)

def pprint_val(self, x):
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
Expand Down Expand Up @@ -790,7 +802,7 @@ def __call__(self, x, pos=None):
if usetex:
return '$0$'
else:
return '$\mathdefault{0}$'
return '$%s$' % _mathdefault('0')

fx = math.log(abs(x)) / math.log(b)
is_decade = is_close_to_int(fx)
Expand All @@ -810,17 +822,18 @@ def __call__(self, x, pos=None):
return (r'$%s%s^{%.2f}$') % \
(sign_string, base, fx)
else:
return ('$\mathdefault{%s%s^{%.2f}}$') % \
(sign_string, base, fx)
return ('$%s$' % _mathdefault(
'%s%s^{%.2f}' %
(sign_string, base, fx)))
else:
if usetex:
return (r'$%s%s^{%d}$') % (sign_string,
base,
nearest_long(fx))
else:
return (r'$\mathdefault{%s%s^{%d}}$') % (sign_string,
base,
nearest_long(fx))
return ('$%s$' % _mathdefault(
'%s%s^{%d}' %
(sign_string, base, nearest_long(fx))))


class LogitFormatter(Formatter):
Expand Down

0 comments on commit 34cf792

Please sign in to comment.