In Matlab, you can create a plot, and then calling "zoom
> on" does the same thing as clicking the zoom button in
> MPL: it just gives zooming context to mouse clicks inside
> the axes. It would be helpful to know how to give such
> context to mouse clicks without having to include toolbar2
> in a figure.
Indeed. Unfortunately, in the current implementation, all the logic
is in the toolbar itself. On the dev list there was some discussion
in the last few weeks on how to modularize the toolbar base class code
(matplotlib.backend_bases.NavigationToolbar2), with an implementation
that factored out all of this code into independent pieces. This was
done to support a user customizable and extensible toolbar, but might
have wider application as this thread suggests, eg to support a
default navigation mode in the absence of any toolbar at all.
Unfortunately, I haven't had time to investigate this or include it as
a patch yet.
So in the current implementation, you have to call the 'pan' method of
the toolbar to set the pan/zoom functionality and the 'zoom' method to
activate zoom to rect.
The following untested code should work across backends from the
matlab interface (using the API, you can access the toolbar instance
manager = get_current_fig_manager()
toolbar = manager.canvas.toolbar
toolbar.pan() # activate pan w/ left and zoom w/ right by default
Note that calling this function toggles the current state, as does the
I think your idea of adding a 'zoom on' function which can be called
from the matlab interface is a good one; any idea if there is a matlab
analog for activating zoom to rect?