File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -498,13 +498,19 @@ def _set_orderOfMagnitude(self,range):
498
498
499
499
def _set_format (self ):
500
500
# set the format string to format all the ticklabels
501
- # The floating point black magic (adding 1e-15 and formatting
502
- # to 8 digits) may warrant review and cleanup.
503
- locs = (np .asarray (self .locs )- self .offset ) / 10 ** self .orderOfMagnitude + 1e-15
504
- sigfigs = [len (str ('%1.8f' % loc ).split ('.' )[1 ].rstrip ('0' )) \
505
- for loc in locs ]
506
- sigfigs .sort ()
507
- self .format = '%1.' + str (sigfigs [- 1 ]) + 'f'
501
+ locs = (np .asarray (self .locs )- self .offset ) / 10 ** self .orderOfMagnitude
502
+ loc_range_oom = int (math .floor (math .log10 (np .ptp (locs ))))
503
+ # first estimate:
504
+ sigfigs = max (0 , 3 - loc_range_oom )
505
+ # refined estimate:
506
+ thresh = 1e-3 * 10 ** loc_range_oom
507
+ while sigfigs >= 0 :
508
+ if np .abs (locs - np .round (locs , decimals = sigfigs )).max () < thresh :
509
+ sigfigs -= 1
510
+ else :
511
+ break
512
+ sigfigs += 1
513
+ self .format = '%1.' + str (sigfigs ) + 'f'
508
514
if self ._usetex :
509
515
self .format = '$%s$' % self .format
510
516
elif self ._useMathText :
You can’t perform that action at this time.
0 commit comments