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 094007f

Browse filesBrowse files
committed
Merge pull request #6337 from gepcel/useMathText
Add a 'useMathText' param to method 'ticklabel_format'
2 parents 6b45409 + d87e38d commit 094007f
Copy full SHA for 094007f

File tree

Expand file treeCollapse file tree

2 files changed

+44
-25
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-25
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+32-24Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,30 +2483,32 @@ def ticklabel_format(self, **kwargs):
24832483
24842484
Optional keyword arguments:
24852485
2486-
============ =========================================
2487-
Keyword Description
2488-
============ =========================================
2489-
*style* [ 'sci' (or 'scientific') | 'plain' ]
2490-
plain turns off scientific notation
2491-
*scilimits* (m, n), pair of integers; if *style*
2492-
is 'sci', scientific notation will
2493-
be used for numbers outside the range
2494-
10`m`:sup: to 10`n`:sup:.
2495-
Use (0,0) to include all numbers.
2496-
*useOffset* [True | False | offset]; if True,
2497-
the offset will be calculated as needed;
2498-
if False, no offset will be used; if a
2499-
numeric offset is specified, it will be
2500-
used.
2501-
*axis* [ 'x' | 'y' | 'both' ]
2502-
*useLocale* If True, format the number according to
2503-
the current locale. This affects things
2504-
such as the character used for the
2505-
decimal separator. If False, use
2506-
C-style (English) formatting. The
2507-
default setting is controlled by the
2508-
axes.formatter.use_locale rcparam.
2509-
============ =========================================
2486+
============== =========================================
2487+
Keyword Description
2488+
============== =========================================
2489+
*style* [ 'sci' (or 'scientific') | 'plain' ]
2490+
plain turns off scientific notation
2491+
*scilimits* (m, n), pair of integers; if *style*
2492+
is 'sci', scientific notation will
2493+
be used for numbers outside the range
2494+
10`m`:sup: to 10`n`:sup:.
2495+
Use (0,0) to include all numbers.
2496+
*useOffset* [True | False | offset]; if True,
2497+
the offset will be calculated as needed;
2498+
if False, no offset will be used; if a
2499+
numeric offset is specified, it will be
2500+
used.
2501+
*axis* [ 'x' | 'y' | 'both' ]
2502+
*useLocale* If True, format the number according to
2503+
the current locale. This affects things
2504+
such as the character used for the
2505+
decimal separator. If False, use
2506+
C-style (English) formatting. The
2507+
default setting is controlled by the
2508+
axes.formatter.use_locale rcparam.
2509+
*useMathText* If True, render the offset and scientific
2510+
notation in mathtext
2511+
============== =========================================
25102512
25112513
Only the major ticks are affected.
25122514
If the method is called when the
@@ -2519,6 +2521,7 @@ def ticklabel_format(self, **kwargs):
25192521
scilimits = kwargs.pop('scilimits', None)
25202522
useOffset = kwargs.pop('useOffset', None)
25212523
useLocale = kwargs.pop('useLocale', None)
2524+
useMathText = kwargs.pop('useMathText', None)
25222525
axis = kwargs.pop('axis', 'both').lower()
25232526
if scilimits is not None:
25242527
try:
@@ -2560,6 +2563,11 @@ def ticklabel_format(self, **kwargs):
25602563
self.xaxis.major.formatter.set_useLocale(useLocale)
25612564
if axis == 'both' or axis == 'y':
25622565
self.yaxis.major.formatter.set_useLocale(useLocale)
2566+
if useMathText is not None:
2567+
if axis == 'both' or axis == 'x':
2568+
self.xaxis.major.formatter.set_useMathText(useMathText)
2569+
if axis == 'both' or axis == 'y':
2570+
self.yaxis.major.formatter.set_useMathText(useMathText)
25632571
except AttributeError:
25642572
raise AttributeError(
25652573
"This method only works with the ScalarFormatter.")

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
509509
self._usetex = rcParams['text.usetex']
510510
if useMathText is None:
511511
useMathText = rcParams['axes.formatter.use_mathtext']
512-
self._useMathText = useMathText
512+
self.set_useMathText(useMathText)
513513
self.orderOfMagnitude = 0
514514
self.format = ''
515515
self._scientific = True
@@ -542,6 +542,17 @@ def set_useLocale(self, val):
542542

543543
useLocale = property(fget=get_useLocale, fset=set_useLocale)
544544

545+
def get_useMathText(self):
546+
return self._useMathText
547+
548+
def set_useMathText(self, val):
549+
if val is None:
550+
self._useMathText = rcParams['axes.formatter.use_mathtext']
551+
else:
552+
self._useMathText = val
553+
554+
useMathText = property(fget=get_useMathText, fset=set_useMathText)
555+
545556
def fix_minus(self, s):
546557
"""
547558
Replace hyphens with a unicode minus.

0 commit comments

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