@@ -279,21 +279,24 @@ def get_offset(self):
279
279
def set_locs (self , locs ):
280
280
self .locs = locs
281
281
282
- def fix_minus (self , s ):
283
- """
284
- Some classes may want to replace a hyphen for minus with the
285
- proper unicode symbol (U+2212) for typographical correctness.
286
- The default is to not replace it.
282
+ @staticmethod
283
+ def fix_minus (s ):
284
+ """
285
+ Some classes may want to replace a hyphen for minus with the proper
286
+ unicode symbol (U+2212) for typographical correctness. This is a
287
+ helper method to perform such a replacement when it is enabled via
288
+ :rc:`axes.unicode_minus`.
289
+ """
290
+ # Additionally, we disable the replacement when using usetex without
291
+ # unicode support (this is deprecated, i.e., in a future version,
292
+ # unicode support will always be enabled).
293
+ if (rcParams ['axes.unicode_minus' ]
294
+ and (rcParams ['text.latex.unicode' ]
295
+ or not rcParams ['text.usetex' ])):
296
+ return s .replace ('-' , '\N{MINUS SIGN} ' )
297
+ else :
298
+ return s
287
299
288
- Note, if you use this method, e.g., in :meth:`format_data` or
289
- call, you probably don't want to use it for
290
- :meth:`format_data_short` since the toolbar uses this for
291
- interactive coord reporting and I doubt we can expect GUIs
292
- across platforms will handle the unicode correctly. So for
293
- now the classes that override :meth:`fix_minus` should have an
294
- explicit :meth:`format_data_short` method
295
- """
296
- return s
297
300
298
301
def _set_locator (self , locator ):
299
302
"""Subclasses may want to override this to set a locator."""
@@ -564,15 +567,6 @@ def set_useMathText(self, val):
564
567
565
568
useMathText = property (fget = get_useMathText , fset = set_useMathText )
566
569
567
- def fix_minus (self , s ):
568
- """
569
- Replace hyphens with a unicode minus.
570
- """
571
- if rcParams ['text.usetex' ] or not rcParams ['axes.unicode_minus' ]:
572
- return s
573
- else :
574
- return s .replace ('-' , '\N{MINUS SIGN} ' )
575
-
576
570
def __call__ (self , x , pos = None ):
577
571
"""
578
572
Return the format for tick value *x* at position *pos*.
@@ -623,13 +617,10 @@ def set_powerlimits(self, lims):
623
617
self ._powerlimits = lims
624
618
625
619
def format_data_short (self , value ):
626
- """
627
- Return a short formatted string representation of a number.
628
- """
629
- if self ._useLocale :
630
- return locale .format_string ('%-12g' , (value ,))
631
- else :
632
- return '%-12g' % value
620
+ # docstring inherited
621
+ return self .fix_minus (
622
+ locale .format_string ('%-12g' , (value ,)) if self ._useLocale else
623
+ '%-12g' % value )
633
624
634
625
def format_data (self , value ):
635
626
"""
@@ -1033,10 +1024,8 @@ def format_data(self, value):
1033
1024
return value
1034
1025
1035
1026
def format_data_short (self , value ):
1036
- """
1037
- Return a short formatted string representation of a number.
1038
- """
1039
- return '%-12g' % value
1027
+ # docstring inherited
1028
+ return self .fix_minus ('%-12g' % value )
1040
1029
1041
1030
@cbook .deprecated ("3.1" )
1042
1031
def pprint_val (self , * args , ** kwargs ):
@@ -1459,12 +1448,6 @@ def set_useMathText(self, val):
1459
1448
1460
1449
useMathText = property (fget = get_useMathText , fset = set_useMathText )
1461
1450
1462
- def fix_minus (self , s ):
1463
- """
1464
- Replace hyphens with a unicode minus.
1465
- """
1466
- return ScalarFormatter .fix_minus (self , s )
1467
-
1468
1451
def __call__ (self , x , pos = None ):
1469
1452
s = "%s%s" % (self .format_eng (x ), self .unit )
1470
1453
# Remove the trailing separator when there is neither prefix nor unit
0 commit comments