Max iterations (=1000) during X axis label placement reached
Closed this issue · 4 comments
I'm seeing this printed just before a plot is generated:
tplot/utils.py:160: UserWarning: Max iterations (=1000) during X axis label placement reached.
warn(
I'm afraid it's not a useful message. I'm not doing anything unreasonable, so tplot
should ideally work without this warning.
I had just 13 data points. I guess tplot
was trying to plot either too many x-axis values, and/or too closely, and/or with too many decimal places. The warning actually went away with 14 data points; it now shows one less decimal place for each label. Still, it would be better if it didn't happen.
Looks like you've found a case where it gets stuck in an infinite loop while trying to fit in all the labels for the X axis. That should never happen, so it's definitely a bug. I put in that warning message just so if it ever happened, at least it would tell you something's wrong and stop iterating instead of just running forever.
Could you post a minimum reproducible code example that generates this warning?
import tplot
fig = tplot.Figure(width=89, height=21)
fig_x = [10.218555833333333, 10.296509722222222, 10.345679444444444, 10.598930833333334, 10.754183888888889, 10.942900833333333, 11.270388888888888, 11.320473611111112, 11.544523055555555, 11.570423611111112, 11.709953333333333, 12.153498055555556]
fig_y = list(range(1, 13))
fig.line(x=fig_x, y=fig_y)
# tplot/utils.py:160: UserWarning: Max iterations (=1000) during X axis label placement reached.
# warn(
fig.show()
# tplot/utils.py:160: UserWarning: Max iterations (=1000) during X axis label placement reached.
# warn(
Thanks, I can reproduce the warning with your code. I'll have a look at it when I have time.
Should be fixed with the new release. Turns out it was an instability in the optimization loop caused by too big of a step size.
I also lowered the number of X ticks being drawn to prevent the labels from crowding too much.