@@ -657,12 +657,12 @@ def format_data(self, value):
657
657
# docstring inherited
658
658
e = math .floor (math .log10 (abs (value )))
659
659
s = round (value / 10 ** e , 10 )
660
- exponent = self ._format_maybe_minus_and_locale ("%d" , e )
661
660
significand = self ._format_maybe_minus_and_locale (
662
661
"%d" if s % 1 == 0 else "%1.10g" , s )
663
662
if e == 0 :
664
663
return significand
665
- elif self ._useMathText or self ._usetex :
664
+ exponent = self ._format_maybe_minus_and_locale ("%d" , e )
665
+ if self ._useMathText or self ._usetex :
666
666
exponent = "10^{%s}" % exponent
667
667
return (exponent if s == 1 # reformat 1x10^y as 10^y
668
668
else rf"{ significand } \times { exponent } " )
@@ -675,7 +675,6 @@ def get_offset(self):
675
675
"""
676
676
if len (self .locs ) == 0 :
677
677
return ''
678
- s = ''
679
678
if self .orderOfMagnitude or self .offset :
680
679
offsetStr = ''
681
680
sciNotStr = ''
@@ -694,8 +693,8 @@ def get_offset(self):
694
693
s = fr'${ sciNotStr } \mathdefault{{{ offsetStr } }}$'
695
694
else :
696
695
s = '' .join ((sciNotStr , offsetStr ))
697
-
698
- return self . fix_minus ( s )
696
+ return self . fix_minus ( s )
697
+ return ''
699
698
700
699
def set_locs (self , locs ):
701
700
# docstring inherited
@@ -1055,9 +1054,6 @@ def _non_decade_format(self, sign_string, base, fx, usetex):
1055
1054
1056
1055
def __call__ (self , x , pos = None ):
1057
1056
# docstring inherited
1058
- usetex = mpl .rcParams ['text.usetex' ]
1059
- min_exp = mpl .rcParams ['axes.formatter.min_exponent' ]
1060
-
1061
1057
if x == 0 : # Symlog
1062
1058
return r'$\mathdefault{0}$'
1063
1059
@@ -1070,23 +1066,25 @@ def __call__(self, x, pos=None):
1070
1066
is_x_decade = _is_close_to_int (fx )
1071
1067
exponent = round (fx ) if is_x_decade else np .floor (fx )
1072
1068
coeff = round (b ** (fx - exponent ))
1073
- if is_x_decade :
1074
- fx = round (fx )
1075
1069
1076
1070
if self .labelOnlyBase and not is_x_decade :
1077
1071
return ''
1078
1072
if self ._sublabels is not None and coeff not in self ._sublabels :
1079
1073
return ''
1080
1074
1075
+ if is_x_decade :
1076
+ fx = round (fx )
1077
+
1081
1078
# use string formatting of the base if it is not an integer
1082
1079
if b % 1 == 0.0 :
1083
1080
base = '%d' % b
1084
1081
else :
1085
1082
base = '%s' % b
1086
1083
1087
- if abs (fx ) < min_exp :
1084
+ if abs (fx ) < mpl . rcParams [ 'axes.formatter.min_exponent' ] :
1088
1085
return r'$\mathdefault{%s%g}$' % (sign_string , x )
1089
1086
elif not is_x_decade :
1087
+ usetex = mpl .rcParams ['text.usetex' ]
1090
1088
return self ._non_decade_format (sign_string , base , fx , usetex )
1091
1089
else :
1092
1090
return r'$\mathdefault{%s%s^{%d}}$' % (sign_string , base , fx )
@@ -1554,7 +1552,7 @@ def symbol(self):
1554
1552
symbol = self ._symbol
1555
1553
if not symbol :
1556
1554
symbol = ''
1557
- elif mpl .rcParams ['text.usetex' ] and not self . _is_latex :
1555
+ elif not self . _is_latex and mpl .rcParams ['text.usetex' ]:
1558
1556
# Source: http://www.personal.ceu.hu/tex/specchar.htm
1559
1557
# Backslash must be first for this to work correctly since
1560
1558
# it keeps getting added in
@@ -1801,8 +1799,6 @@ def __call__(self):
1801
1799
1802
1800
def tick_values (self , vmin , vmax ):
1803
1801
vmin , vmax = mtransforms .nonsingular (vmin , vmax , expander = 0.05 )
1804
- if vmax < vmin :
1805
- vmin , vmax = vmax , vmin
1806
1802
1807
1803
if (vmin , vmax ) in self .presets :
1808
1804
return self .presets [(vmin , vmax )]
@@ -2356,13 +2352,13 @@ def tick_values(self, vmin, vmax):
2356
2352
numdec = math .floor (log_vmax ) - math .ceil (log_vmin )
2357
2353
2358
2354
if isinstance (self ._subs , str ):
2359
- _first = 2.0 if self ._subs == 'auto' else 1.0
2360
2355
if numdec > 10 or b < 3 :
2361
2356
if self ._subs == 'auto' :
2362
2357
return np .array ([]) # no minor or major ticks
2363
2358
else :
2364
2359
subs = np .array ([1.0 ]) # major ticks
2365
2360
else :
2361
+ _first = 2.0 if self ._subs == 'auto' else 1.0
2366
2362
subs = np .arange (_first , b )
2367
2363
else :
2368
2364
subs = self ._subs
@@ -2386,23 +2382,14 @@ def tick_values(self, vmin, vmax):
2386
2382
decades = np .arange (math .floor (log_vmin ) - stride ,
2387
2383
math .ceil (log_vmax ) + 2 * stride , stride )
2388
2384
2389
- if hasattr (self , '_transform' ):
2390
- ticklocs = self ._transform .inverted ().transform (decades )
2391
- if have_subs :
2392
- if stride == 1 :
2393
- ticklocs = np .ravel (np .outer (subs , ticklocs ))
2394
- else :
2395
- # No ticklocs if we have >1 decade between major ticks.
2396
- ticklocs = np .array ([])
2397
- else :
2398
- if have_subs :
2399
- if stride == 1 :
2400
- ticklocs = np .concatenate (
2401
- [subs * decade_start for decade_start in b ** decades ])
2402
- else :
2403
- ticklocs = np .array ([])
2385
+ if have_subs :
2386
+ if stride == 1 :
2387
+ ticklocs = np .concatenate (
2388
+ [subs * decade_start for decade_start in b ** decades ])
2404
2389
else :
2405
- ticklocs = b ** decades
2390
+ ticklocs = np .array ([])
2391
+ else :
2392
+ ticklocs = b ** decades
2406
2393
2407
2394
_log .debug ('ticklocs %r' , ticklocs )
2408
2395
if (len (subs ) > 1
@@ -2422,8 +2409,8 @@ def view_limits(self, vmin, vmax):
2422
2409
vmin , vmax = self .nonsingular (vmin , vmax )
2423
2410
2424
2411
if mpl .rcParams ['axes.autolimit_mode' ] == 'round_numbers' :
2425
- vmin = _decade_less_equal (vmin , self . _base )
2426
- vmax = _decade_greater_equal (vmax , self . _base )
2412
+ vmin = _decade_less_equal (vmin , b )
2413
+ vmax = _decade_greater_equal (vmax , b )
2427
2414
2428
2415
return vmin , vmax
2429
2416
@@ -2503,7 +2490,6 @@ def __call__(self):
2503
2490
return self .tick_values (vmin , vmax )
2504
2491
2505
2492
def tick_values (self , vmin , vmax ):
2506
- base = self ._base
2507
2493
linthresh = self ._linthresh
2508
2494
2509
2495
if vmax < vmin :
@@ -2540,6 +2526,8 @@ def tick_values(self, vmin, vmax):
2540
2526
# Check if linear range is present
2541
2527
has_b = (has_a and vmax > - linthresh ) or (has_c and vmin < linthresh )
2542
2528
2529
+ base = self ._base
2530
+
2543
2531
def get_log_range (lo , hi ):
2544
2532
lo = np .floor (np .log (lo ) / np .log (base ))
2545
2533
hi = np .ceil (np .log (hi ) / np .log (base ))
@@ -2573,11 +2561,7 @@ def get_log_range(lo, hi):
2573
2561
if has_c :
2574
2562
decades .extend (base ** (np .arange (c_lo , c_hi , stride )))
2575
2563
2576
- # Add the subticks if requested
2577
- if self ._subs is None :
2578
- subs = np .arange (2.0 , base )
2579
- else :
2580
- subs = np .asarray (self ._subs )
2564
+ subs = np .asarray (self ._subs )
2581
2565
2582
2566
if len (subs ) > 1 or subs [0 ] != 1.0 :
2583
2567
ticklocs = []
@@ -2604,8 +2588,7 @@ def view_limits(self, vmin, vmax):
2604
2588
vmin = _decade_less (vmin , b )
2605
2589
vmax = _decade_greater (vmax , b )
2606
2590
2607
- result = mtransforms .nonsingular (vmin , vmax )
2608
- return result
2591
+ return mtransforms .nonsingular (vmin , vmax )
2609
2592
2610
2593
2611
2594
class AsinhLocator (Locator ):
@@ -2773,7 +2756,7 @@ def tick_values(self, vmin, vmax):
2773
2756
# linscale: ... 1e-3 1e-2 1e-1 1/2 1-1e-1 1-1e-2 1-1e-3 ...
2774
2757
# b-scale : ... -3 -2 -1 0 1 2 3 ...
2775
2758
def ideal_ticks (x ):
2776
- return 10 ** x if x < 0 else 1 - (10 ** (- x )) if x > 0 else 1 / 2
2759
+ return 10 ** x if x < 0 else 1 - (10 ** (- x )) if x > 0 else 0.5
2777
2760
2778
2761
vmin , vmax = self .nonsingular (vmin , vmax )
2779
2762
binf = int (
0 commit comments