You can use your own axis class. In your case, you can inherit from matplotlib.axes.Axes and change the drag_pan method to always act as if the "x" key was pressed. However, scaling does not appear to be defined in this class. The following will only allow x-axis panning:
import matplotlib import matplotlib.pyplot as plt class My_Axes(matplotlib.axes.Axes): name = "My_Axes" def drag_pan(self, button, key, x, y): matplotlib.axes.Axes.drag_pan(self, button, 'x', x, y)
To scale, you may need to look at the toolbar control. The NavigationToolbar2 class has a drag_zoom method that seems to matter here, but tracking how this works is quickly complicated by the fact that different backends have their own versions (e.g. NavigationToolbar2TkAgg
change
You can monkeypatch desired behavior in:
import types def press_zoom(self, event): event.key='x' matplotlib.backends.backend_tkagg.NavigationToolbar2TkAgg.press_zoom(self,event) figure.canvas.toolbar.press_zoom=types.MethodType(press_zoom, figure.canvas.toolbar)
You can do it right and subclass the toolbar, but then you need to instantiate the Figure, FigureCanvas and your NavigationToolbar and put them in a Tk application or something like that. I donβt think there is a very simple way to just use your own toolbar with a simple build interface.
source share