Skip to content

No explicit mathdefault in log formatter #5587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,5 @@ animation.convert_path: convert # Path to ImageMagick's convert binary.
# is also the name of a system tool.
animation.convert_args:
animation.html: none

_internal.classic_mode: True
9 changes: 8 additions & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,14 @@ def validate_cycler(s):
'animation.convert_path': ['convert', six.text_type],
# Additional arguments for mencoder movie writer (using pipes)

'animation.convert_args': [[], validate_stringlist]}
'animation.convert_args': [[], validate_stringlist],

# Classic (pre 2.0) compatibility mode
# This is used for things that are hard to make backward compatible
# with a sane rcParam alone. This does *not* turn on classic mode
# altogether. For that use `matplotlib.style.use('classic')`.
'_internal.classic_mode': [False, validate_bool]
}


if __name__ == '__main__':
Expand Down
33 changes: 23 additions & 10 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
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