Question

In my matplotlib figure, I have multiple axes. I can use navigation toolbar pan & zoom on every axes. But I want to know which axes is panned or zoomed. How to get that information. Also if that axes is first zoomed and then reverted using Back button, so it is back to its initial state so in that case I do not want that axes info.

In short, I want the info of axes which is modified from initial state only? Plz share your views.

Thanks in advance.

Was it helpful?

Solution

The toolbar keeps track of it's state with an internal stack, however I would not recommend directly accessing that. I am pretty sure that is considered a non-public api and can be broken at will.

Instead, when you construct your figure grab the xlim and ylim of the axes. Later you can loop over fig.axes an check your self

lim_dict = dict()
for ax in fig.axes:
    lim_dict[ax] = (ax.get_xlim(), ax.get_ylim())

def ax_changed(ax):
    old_xlim, old_ylim = lim_dict[ax]
    return np.all(old_xlim == ax.get_xlim()) and np.all(old_ylim == ax.get_ylim())

changed_axes = [ax for ax in figs.axes if ax_changed(ax)]
not_changed_axes = [ax for ax in figs.axes if not ax_changed(ax)]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top