In my plotting application written in Python, I use matplotlib (with TkAgg backend) to draw some data.
This plot is interactive, so the user can drag/zoom the plot region. However, sometimes the application needs to clear the curves and plot them anew - and as a result, the plot rescales to the extent of the curves.
It would be better to keep the user-defined limits. However, calling e.g. ax.get_xlim()
returns the limits that were originally set by ax.set_xlim(...)
, not the current limits that the user has changed by their mouse.
I tried hard to find the solution in the documentation and examples, yet still I could not resolve this simple task: How to get the current limits of interactive matplotlib plot?