@@ -364,7 +364,7 @@ def _tformat(number: float, order: int, precision: int):
364364 formatted = ("{:." + str (precision ) + "e}" ).format (number )
365365 # remove pointless leading 0 in exponent
366366 return "" .join ([formatted [:- 2 ], formatted [- 1 ]])
367- if order + precision < 0 :
367+ if order + precision == 0 :
368368 return str (round (number ))
369369 return str (number )
370370
@@ -377,7 +377,7 @@ def _trylabel(
377377 Attempts to find label positions that maximize coverage while minimizing
378378 required decimal places.
379379 """
380- # 100 is arbitrary, basically the resolution of the solver
380+ # 100 is arbitrary -- basically the resolution of the solver
381381 grid = np .linspace (bounds [0 ], bounds [1 ], n_ticks * 100 )
382382 labels = sorted (
383383 {_tformat (round (n , order + precision ), order , precision ) for n in grid }
@@ -387,11 +387,12 @@ def _trylabel(
387387 inbounds = (positions <= grid .max ()) & (positions >= grid .min ())
388388 labels , positions = labels [inbounds ], positions [inbounds ]
389389 labels , positions = labels [np .argsort (positions )], np .sort (positions )
390- # NOTE: 20% range cutoff here is totally arbitrary
390+ # NOTE: 15% range cutoff here is totally arbitrary
391+ extent = (grid .max () - grid .min ())
391392 if (
392393 positions .size < n_ticks
393- or abs ((positions .max () - grid .max ()) / grid . max ()) > 0.2
394- or abs ((positions .min () - grid .min ()) / grid . min ()) > 0.2
394+ or abs ((positions .max () - grid .max ()) / extent ) > 0.15
395+ or abs ((positions .min () - grid .min ()) / extent ) > 0.15
395396 ):
396397 # noinspection PyTypeChecker
397398 return labels , False
0 commit comments