Hi Vicent,
On Thursday 03 September 2009 18:14:37 Vicent Mas wrote:
> Hi Matthias,
>
> 2009/9/3 Matthias Michler <[email protected]>:
> > Hi Vicent,
> >
> > I think the following example may help you, althogh their might be a
> > better way:
>
> thanks for your answer. It really helps. I didn't know about the mode
> attribute of navigation toolbars. Inspecting the
> NavigationToolbar2QTAgg class interactively with an IPython shell
> doesn't show such attribute for this class. Maybe it is created
> dynamically when the pan/zoom button is clicked?
I think: The attribute 'mode' is added during the initialisation of the
toolbar (actually it is set during the initalisation of
backend_qt.NavigationToolbar2QT and therefore you can see it directly as
attribute of the abstract class NavigationToolbar2QTAgg, which inherits from
backend_qt.NavigationToolbar2QT).
Therefore the following works:
import matplotlib
matplotlib.use("QTAgg")
import matplotlib.pyplot as plt
print "initialised toolbar : ", plt.get_current_fig_manager().toolbar
print " >%s<" % (plt.get_current_fig_manager().toolbar.mode)
> Now I still have to find out how to distinguish axes pan from axes
> zoom cases. I suppose I can use 'button_press_event' canvas events and
> use the button attribute of these events for knowing if the user is
> doing a pan or a zoom: pan/zoom mode + left button --> user is panning
> axes, pan/zoom mode + right button --> user is zooming axes. Right?
I send you again my previous example with some additional lines. In my opinion
you can use either 'button_press_event' or axes-callbacks to achieve what
you want, but maybe I'm missing something.
regards Matthias
import matplotlib.pyplot as plt
def callback(ax):
""" prints mode of toolbar after limits changed
e.g.
mode : >zoom rect<
mode : >pan/zoom<
"""
print " mode : >%s<" % (plt.get_current_fig_manager().toolbar.mode)
if plt.get_current_fig_manager().toolbar.mode == 'zoom rect':
print "We are in zoom with Rectangle - mode"
elif plt.get_current_fig_manager().toolbar.mode == 'pan/zoom':
print "We are in pan/zoom - mode"
def fct(event):
""" print zoom-mode after 'button_press_event' """
if plt.get_current_fig_manager().toolbar.mode == 'zoom rect':
print "We are in zoom with Rectangle - mode"
elif plt.get_current_fig_manager().toolbar.mode == 'pan/zoom':
print "We are in pan/zoom - mode"
ax = plt.gca()
##ax.callbacks.connect('xlim_changed', callback)
##ax.callbacks.connect('ylim_changed', callback)
plt.connect("button_press_event", fct)
plt.show()
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users