A question about pam/zoom functionality of navigationtoolbar

The question is: how to enable panning/zooming operation to be constrained to the x axis or y axis?

The Tutorial says,
[about Pam Mode] If you
press ‘x’ or ‘y’ while panning, the motion will be contrained to the
x or y axis, respectively
[about Zoom Mode] You can use the
modifier keys ‘x’, ‘y’ or ‘CONTROL’ to constrain the zoom to the x
axes, the y axes, or aspect ratio preserve, respectively.

I find it really works for some examples, such as stock_demo.py.
However, it currently can’t work on my canvas.
Is there any special setting so as to enable the functionality?

Thanks for your guidance in advance.

···


sunzen
<<freedom & enjoyment>>

I’m sad to see that there is no answer to my question over these days.
Active development of matplotlib needs a lot of users.

···

On Oct 31, 2007 11:17 AM, sunzen w. < sunzen@…287…> wrote:

The question is: how to enable panning/zooming operation to be constrained to the x axis or y axis?

The Tutorial says,
[about Pam Mode] If you
press ‘x’ or ‘y’ while panning, the motion will be contrained to the
x or y axis, respectively
[about Zoom Mode] You can use the
modifier keys ‘x’, ‘y’ or ‘CONTROL’ to constrain the zoom to the x
axes, the y axes, or aspect ratio preserve, respectively.

I find it really works for some examples, such as stock_demo.py.
However, it currently can’t work on my canvas.
Is there any special setting so as to enable the functionality?

Thanks for your guidance in advance.


sunzen
<<freedom & enjoyment>>


sunzen
<<freedom & enjoyment>>

I'm not sure what you mean by "can't work on my canvas". Can you provide a small code sample that shows it not working?

Cheers,
Mike

sunzen w. wrote:

···

I'm sad to see that there is no answer to my question over these days.
Active development of matplotlib needs a lot of users.

On Oct 31, 2007 11:17 AM, sunzen w. < sunzen@…287… > <mailto:sunzen@…287…>> wrote:

    The question is: how to enable panning/zooming operation to be
    constrained to the x axis or y axis?

    The Tutorial says,
    [about Pam Mode] If you press 'x' or 'y' while panning, the motion
    will be contrained to the x or y axis, respectively
    [about Zoom Mode] You can use the modifier keys 'x', 'y' or
    'CONTROL' to constrain the zoom to the x axes, the y axes, or aspect
    ratio preserve, respectively.

    I find it really works for some examples, such as stock_demo.py.
    However, it currently can't work on my canvas.
    Is there any special setting so as to enable the functionality?

    Thanks for your guidance in advance.

    -- sunzen
    <<freedom & enjoyment>>

--
sunzen
<<freedom & enjoyment>>

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

I'm not sure what you mean by "can't work on my canvas". Can you
provide a small code sample that shows it not working?

Sunzen,

Here is a reference example in which the x and y constrained panning
do work in my tests with (GTKAgg and mpl svn), and picking is enabled,
so you might start and see if this works for you and if not what is
different about your code. Note that you can only have *either*
panning and zooming enabled, or picking, but not both at the same
time, because both compete for the resource of the mouse via the
widget lock.

import numpy
from pylab import figure, show

X = numpy.random.rand(100, 1000)
xs = numpy.mean(X, axis=1)
ys = numpy.std(X, axis=1)

fig = figure()
ax = fig.add_subplot(111)
ax.set_title('click on point to plot time series')
line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance

def onpick(event):

    if event.artist!=line: return True

    N = len(event.ind)
    if not N: return True

    figi = figure()
    for subplotnum, dataind in enumerate(event.ind):
        ax = figi.add_subplot(N,1,subplotnum+1)
        ax.plot(X[dataind])
        ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]),
                transform=ax.transAxes, va='top')
        ax.set_ylim(-0.5, 1.5)
    figi.show()
    return True

fig.canvas.mpl_connect('pick_event', onpick)

show()

I'm sad to see that there is no answer to my question over these days.
Active development of matplotlib needs a lot of users.

Absolutely true. We have several active developers, and many more
users, so developers tend to prioritize their responses to questions
which provide a clear description of the problem (with version and
environment information) and more importantly, a code sample so we can
see whether we can replicate the problem on our end. When a user
doesn't take the time to prepare such a post so that we can help him
effectively, we tend to move on.

JDH

JDH

···

On Nov 7, 2007 7:17 AM, Michael Droettboom <mdroe@...86...> wrote:

John,
Thank you for your response.

> I'm not sure what you mean by "can't work on my canvas". Can you
> provide a small code sample that shows it not working?

(Mike, i'm sorry for that i forgot to send my last response to matplotlib-users)
I meant the plot can't be constrained to x or y axis when I press 'x'
or 'y' key while operating on the pan mode. Panning plot just
relative to 'x' or 'y' axis is what i want.

Here is a reference example in which the x and y constrained panning
do work in my tests with (GTKAgg and mpl svn), and picking is enabled,
so you might start and see if this works for you and if not what is
different about your code. Note that you can only have *either*
panning and zooming enabled, or picking, but not both at the same
time, because both compete for the resource of the mouse via the
widget lock.

Thanks for your example.
The pan mode works normally in the example, as many examples of
matplotlib package.
Yes, Only either panning/zooming or picking is enabled at one time.

> I'm sad to see that there is no answer to my question over these days.
> Active development of matplotlib needs a lot of users.

Absolutely true. We have several active developers, and many more
users, so developers tend to prioritize their responses to questions
which provide a clear description of the problem (with version and
environment information) and more importantly, a code sample so we can
see whether we can replicate the problem on our end. When a user
doesn't take the time to prepare such a post so that we can help him
effectively, we tend to move on.

Thanks for your detailed explanation. I'm sorry for my brief information.
My system is fedora 7. python version is 2.5, and matplotlib version
is 0.90.0.

I try to rebuild a small sample code, which is attached. Amazingly,
the pan mode is normal for this sample code. However, the problem
existing in my application code is still not yet identified.

What's the possible reasons? What kind of further information i should provide?
I'll keep exploration. Thank you for your guidance.

pan-sample.py (1.75 KB)

···

On Nov 7, 2007 10:13 PM, John Hunter <jdh2358@...287...> wrote:

On Nov 7, 2007 7:17 AM, Michael Droettboom <mdroe@...86...> wrote:

--
sunzen
<<freedom & enjoyment>>

sunzen w. wrote:

I try to rebuild a small sample code, which is attached. Amazingly,
the pan mode is normal for this sample code. However, the problem
existing in my application code is still not yet identified.

What's the possible reasons? What kind of further information i should provide?
I'll keep exploration. Thank you for your guidance.

All I can suggest is that you compare this script you provided (which works) to the one that's broken (your application), and try to determine which difference is causing it to break. Once you've put that difference into a short script and we can reproduce it, we'll have a better idea of what the root cause might be and whether there's a workaround.

Cheers,
Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Mike,
Thank you for your suggestion.
I found that pan mode doesn't work as expected in page of notebook.
The sample code is attached.
Thanks for your further guidance in advance.

pan-sample.py (1.88 KB)

···

On Nov 8, 2007 9:27 PM, Michael Droettboom <mdroe@...86...> wrote:
> All I can suggest is that you compare this script you provided (which

works) to the one that's broken (your application), and try to determine
which difference is causing it to break. Once you've put that
difference into a short script and we can reproduce it, we'll have a
better idea of what the root cause might be and whether there's a
workaround.

Cheers,
Mike

--
sunzen
<<freedom & enjoyment>>

Now that is a well focused question. A little googling revealed that
when a gtk drawing area (eg an matplotlib canvas) is placed in a gtk
notebook, it needs to have the focus to receive key press events.

  http://www.daa.com.au/pipermail/pygtk/2002-August/003190.html

I had hoped it would be enough to do

  canvas.grab_focus()

but apparently it is not (upon testing). But the suggestion from the
link above to use TAB to grab the focus worked in my tests.

JDH

···

On Nov 8, 2007 7:48 PM, sunzen w. <sunzen@...287...> wrote:

Mike,
Thank you for your suggestion.
I found that pan mode doesn't work as expected in page of notebook.
The sample code is attached.
Thanks for your further guidance in advance.

With a little more testing, I find if I grab the focus after showing
the window that the notebook is in, it works as expected:

        notebook = gtk.Notebook()
        win.add(notebook)

        vbox = gtk.VBox()
        fig = mplfigure.Figure(figsize=(5,4), dpi=100)
        canvas = FigureCanvas(fig) # a gtk.DrawingArea

        vbox.pack_start(canvas)
        toolbar = NavigationToolbar(canvas, win)
        vbox.pack_start(toolbar, False, False)

        notebook.insert_page(vbox, gtk.Label('Graph'))

        win.show_all()

        # need to get the focus in a notebook to handle keypress
        # events
        canvas.grab_focus()

···

On Nov 9, 2007 12:37 PM, John Hunter <jdh2358@...287...> wrote:

On Nov 8, 2007 7:48 PM, sunzen w. <sunzen@...287...> wrote:
> Mike,
> Thank you for your suggestion.
> I found that pan mode doesn't work as expected in page of notebook.
> The sample code is attached.
> Thanks for your further guidance in advance.

Now that is a well focused question. A little googling revealed that
when a gtk drawing area (eg an matplotlib canvas) is placed in a gtk
notebook, it needs to have the focus to receive key press events.

  http://www.daa.com.au/pipermail/pygtk/2002-August/003190.html

I had hoped it would be enough to do

  canvas.grab_focus()

but apparently it is not (upon testing). But the suggestion from the
link above to use TAB to grab the focus worked in my tests.

John,

> Now that is a well focused question.

Thank you for your teaching. ^_^.

A little googling revealed that
> when a gtk drawing area (eg an matplotlib canvas) is placed in a gtk
> notebook, it needs to have the focus to receive key press events.

Thank you for the information. It's really the point.

I had hoped it would be enough to do
  canvas.grab_focus()
but apparently it is not (upon testing). But the suggestion from the
link above to use TAB to grab the focus worked in my tests.

With a little more testing, I find if I grab the focus after showing
the window that the notebook is in, it works as expected:

Thank you for your patient test.
Just for information, it is also workable to set current page for
notebook firstly and then grab focus for the drawing area, such as
notebook.set_current_page(pageno)
canvas.grab_focus() #canvas is the view embedded in page $pageno

Thanks again for your help.

···

On Nov 10, 2007 2:41 AM, John Hunter <jdh2358@...287...> wrote:
--
sunzen
<<freedom & enjoyment>>