Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible to use your own axes class. In your case you can inherit from <code>matplotlib.axes.Axes</code> and change the <code>drag_pan</code> method to always act as though the 'x' key is being pressed. However the zooming doesn't seem to be defined in that class. The following will only allow x axis panning:</p> <pre><code>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) # pretend key=='x' matplotlib.projections.register_projection(My_Axes) figure = plt.figure() ax = figure.add_subplot(111, projection="My_Axes") ax.plot([0, 1, 2], [0, 1, 0]) plt.show() </code></pre> <p>For the zooming, you may have to look at the toolbar control itself. The <a href="https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backend_bases.py#L2953" rel="noreferrer">NavigationToolbar2</a> class has the <code>drag_zoom</code> method which seems to be what's relevant here, but tracking down how that works is quickly complicated by the fact that the different backends all have their own versions (e.g. <a href="https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_tkagg.py#L789" rel="noreferrer">NavigationToolbar2TkAgg</a></p> <p><strong>edit</strong></p> <p>You <em>can</em> monkeypatch the desired behaviour in:</p> <pre><code>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) </code></pre> <p>You could do it properly and make a subclass of the toolbar, but you have to then create instances of Figure, FigureCanvas and your NavigationToolbar and put them in a Tk app or something. I don't think there's a really straightforward way to just use your own toolbar with the simple plotting interface.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload