zoom on

jdhunter@...4... wrote:

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.

Would it be possible to add some facilities to get a list of the method associated to each toolbar button in order to call the underlying function directly from within the program?
(I'm not sure this very clear... The idea is to be able to perform some actions automatically while creating figures instead of waiting for mouse button clicks - e.g. the command 'grid(1)' displays grids and this feature could also be accessed from a toolbar button)

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
more directly)

  manager = get_current_fig_manager()
  toolbar = manager.canvas.toolbar
  toolbar.pan() # activate pan w/ left and zoom w/ right by default

Ok, with TkAgg / matplotlib 0.62.4 I just had to use 'manager.toolbar' instead of 'manager.canvas.toolbar'. Obviously pan() is used to move the figure view and zoom() to let the user draw rectangles around the region to be zoomed. This is the last one which I needed:

> manager = get_current_fig_manager()
> manager.toolbar.zoom()

(Thanks, I always knew this would be few code lines!)

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?

Indeed 'zoom' activates zoom to rectangular region as toolbar.zoom() does. The only difference is that zoom in Matlab is able to toggle or to set the zoom state depending on the input args:

zoom -> toggles the zoom
zoom on -> turn it on
zoom off -> turn it off

So the previous code only mimics the first implementation. As I don't know how to get the zoom state, I cannot propose a full Matlab replacement to the 'zoom' function. Perhaps the modularized toolbar could introduce this feature for each button with a simple code like this:

def myButtonCallBackFunc(state=-1):
  if state == -1:
    # toggle
  elif state == 0:
    # reset
  elif state == 1;
    # set
    #raise error

Doing this each toolbar button would be easy to toggle or turn on/off from code and we could easily implement a matplotlib version of the Matlab 'zoom' function.

JM. Philippe