SymmetricalLogLocator adds extra erroneous major ticks due to floating-point precision error #18757
Labels
keep
Items to be ignored by the “Stale” Github Action
status: confirmed bug
topic: ticks axis labels
topic: transforms and scales
Bug summary:
SymmetricalLogLocator
appears to suffer a floating-point precision error in calculating the boundaries of the log regions of asymlog
plot, which results in the addition of extra major ticks in the linear region of the plot.Code reproducing the issue:
(OS=Windows 10, Python=3.8.3, Anaconda=2020.07)
Output (with error highlighted in red):

Discussion:
Major ticks generated by
SymmetricalLogLocator
sometimes include an extra tick in the linear region:SymmetricalLogLocator
calculates the inner (towards zero) boundaries of the log regions via the following base-agnostic logarithm:However, when
base=10
, some power-of-ten thresholds cause floating-point precision problems:With the
np.floor()
calculation, this introduces an additional erroneous innermost major tick.@dstansby proposed a possible fix to a related issue in #14309, which changes
np.floor()
tonp.ceil()
. This looks like it would work with the precision errors I identified above, which all err towards zero, but it would fail with bases that err away from zero, e.g.,base=5
:Other possible solutions I can think of: (1) rounding to
base
within a certain proximity, or (2) adding a special case whenbase=10
whereinnp.log10()
is used instead ofnp.log()/np.log(base)
.The text was updated successfully, but these errors were encountered: