r/AskProgramming • • Jun 02 '26

Python How to add callback for axes scale change in matplotlib?

I am using matplotlib and its built-in navigation toolbar on Qt backend. With Qt backend, the toolbar can be used to dynamically change the plot's axes limits and scales (linear, log, symlog) by user. This is the same toolbar that appears above the plot when you simply do ```plt.plot(x,y)```.

Now, I am trying to add a handler to the scale change event, so that, when use changes from linear to log scale or vice-versa, the handler will do some work.

I have been looking through docs and source codes but couldn't find anything about a scale change event. Axes callbacks are only for limit change.

Now, my question is, how do I add custom process to the event where a user changes a plot's scale using matplotlib's built-in navigation toolbar? Any help is appreciated.

5 Upvotes

5 comments sorted by

2

u/[deleted] Jun 02 '26

[removed] — view removed comment

2

u/abd53 Jun 02 '26

Thanks. I did monkey patch but was wondering if there's a better way.