pick events don't work with twiny

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

pick events don't work with twiny

Neal Becker
I find that pick events are fine until I add twiny.  In that case, nothing
happens when clicking.

THe code outline is like:

fig, ax = plt.subplots()
ax2 = ax.twiny()
ax.semilogy(...)
fig.canvas.mpl_connect('pick_event', onpick)
ax2_xaxis = np.linspace (*ax.get_xlim(), endpoint=True,)/conversion
ax2.semilogy (ax2_xaxis, np.ones (len(ax2_xaxis)) * 1e-3, alpha=0)
ax2.set_xlabel(...)
...

removing all the lines about ax2 will restore pick function.

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: pick events don't work with twiny

Benjamin Root
The problem is that the second axes is getting the pick events, because it is on top of the first axes. This has been a problem for a long time, and we haven't found a good solution for it.

Ben Root

On Tue, Jan 30, 2018 at 10:10 AM, Neal Becker <[hidden email]> wrote:
I find that pick events are fine until I add twiny.  In that case, nothing
happens when clicking.

THe code outline is like:

fig, ax = plt.subplots()
ax2 = ax.twiny()
ax.semilogy(...)
fig.canvas.mpl_connect('pick_event', onpick)
ax2_xaxis = np.linspace (*ax.get_xlim(), endpoint=True,)/conversion
ax2.semilogy (ax2_xaxis, np.ones (len(ax2_xaxis)) * 1e-3, alpha=0)
ax2.set_xlabel(...)
...

removing all the lines about ax2 will restore pick function.

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: pick events don't work with twiny

Neal Becker
Benjamin Root wrote:

> The problem is that the second axes is getting the pick events, because it
> is on top of the first axes. This has been a problem for a long time, and
> we haven't found a good solution for it.
>
> Ben Root
>

That was my guess.  Is there any workaround?

> On Tue, Jan 30, 2018 at 10:10 AM, Neal Becker
> <[hidden email]> wrote:
>
>> I find that pick events are fine until I add twiny.  In that case,
>> nothing happens when clicking.
>>
>> THe code outline is like:
>>
>> fig, ax = plt.subplots()
>> ax2 = ax.twiny()
>> ax.semilogy(...)
>> fig.canvas.mpl_connect('pick_event', onpick)
>> ax2_xaxis = np.linspace (*ax.get_xlim(), endpoint=True,)/conversion
>> ax2.semilogy (ax2_xaxis, np.ones (len(ax2_xaxis)) * 1e-3, alpha=0)
>> ax2.set_xlabel(...)
>> ...
>>
>> removing all the lines about ax2 will restore pick function.
>>


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: pick events don't work with twiny

Benjamin Root
I seem to recall someone once messing around with the zorder of the axes object, but I forget if that actually worked. Of course the other workaround is to make the axes with the pickable objects be the twined axes.

Ben Root


On Tue, Jan 30, 2018 at 11:15 AM, Neal Becker <[hidden email]> wrote:
Benjamin Root wrote:

> The problem is that the second axes is getting the pick events, because it
> is on top of the first axes. This has been a problem for a long time, and
> we haven't found a good solution for it.
>
> Ben Root
>

That was my guess.  Is there any workaround?

> On Tue, Jan 30, 2018 at 10:10 AM, Neal Becker
> <[hidden email]> wrote:
>
>> I find that pick events are fine until I add twiny.  In that case,
>> nothing happens when clicking.
>>
>> THe code outline is like:
>>
>> fig, ax = plt.subplots()
>> ax2 = ax.twiny()
>> ax.semilogy(...)
>> fig.canvas.mpl_connect('pick_event', onpick)
>> ax2_xaxis = np.linspace (*ax.get_xlim(), endpoint=True,)/conversion
>> ax2.semilogy (ax2_xaxis, np.ones (len(ax2_xaxis)) * 1e-3, alpha=0)
>> ax2.set_xlabel(...)
>> ...
>>
>> removing all the lines about ax2 will restore pick function.
>>


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: pick events don't work with twiny

Jody Klymak
Eric Firing took s stab at it a couple of years ago: https://github.com/matplotlib/matplotlib/pull/2986

Obviously this is hard - if you stick a couple of artists on top of one another, deciding which one gets a mouse event is ambiguous. 

I forget exactly how picking architecture works, but its seems *possible* to let each axes artist accept pick events.  Then they can duke it out over who actually does something with it.  But I’m not sure axes can actually do that at the present.

I also wonder if your `onpick` function can be made more sophisticated - I assume it knows what axis to look for picks in - maybe it could look in the twinned axis for a pick as well? 

Cheers,  Jody

On 30 Jan 2018, at 08:27, Benjamin Root <[hidden email]> wrote:

I seem to recall someone once messing around with the zorder of the axes object, but I forget if that actually worked. Of course the other workaround is to make the axes with the pickable objects be the twined axes.

Ben Root


On Tue, Jan 30, 2018 at 11:15 AM, Neal Becker <[hidden email]> wrote:
Benjamin Root wrote:

> The problem is that the second axes is getting the pick events, because it
> is on top of the first axes. This has been a problem for a long time, and
> we haven't found a good solution for it.
>
> Ben Root
>

That was my guess.  Is there any workaround?

> On Tue, Jan 30, 2018 at 10:10 AM, Neal Becker
> <[hidden email]> wrote:
>
>> I find that pick events are fine until I add twiny.  In that case,
>> nothing happens when clicking.
>>
>> THe code outline is like:
>>
>> fig, ax = plt.subplots()
>> ax2 = ax.twiny()
>> ax.semilogy(...)
>> fig.canvas.mpl_connect('pick_event', onpick)
>> ax2_xaxis = np.linspace (*ax.get_xlim(), endpoint=True,)/conversion
>> ax2.semilogy (ax2_xaxis, np.ones (len(ax2_xaxis)) * 1e-3, alpha=0)
>> ax2.set_xlabel(...)
>> ...
>>
>> removing all the lines about ax2 will restore pick function.
>>


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Jody Klymak    






_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: pick events don't work with twiny

"V. Armando Solé"
In reply to this post by Benjamin Root
On 30/01/2018 17:27, Benjamin Root wrote:
> I seem to recall someone once messing around with the zorder of the
> axes object, but I forget if that actually worked. Of course the other
> workaround is to make the axes with the pickable objects be the twined
> axes.
>

I'm using something on those lines since some time that works for me
since quite some time. Here is a code fragment:

            self.ax = self.fig.add_axes([.15, .15, .75, .75], label="left")
            self.ax2 = self.ax.twinx()
            self.ax2.set_label("right")
            # critical for picking!!!!
            self.ax2.set_zorder(0)
            self.ax2.set_autoscaley_on(True)
            self.ax.set_zorder(1)
            self.fig.sca(self.ax)

Best regards,

Armando

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: pick events don't work with twiny

Joe Kington
If you know the artists you'd like to fire pick events for, you can work around it in a few different ways.  One option is to bind to mouse events and handle firing off pick events in that callback.

Here's how mpldatacursor gets around the twinx/twiny issue: https://github.com/joferkington/mpldatacursor/blob/master/mpldatacursor/datacursor.py#L658

Cheers,
-Joe

On Wed, Jan 31, 2018 at 1:31 AM, V. Armando Solé <[hidden email]> wrote:
On 30/01/2018 17:27, Benjamin Root wrote:
> I seem to recall someone once messing around with the zorder of the
> axes object, but I forget if that actually worked. Of course the other
> workaround is to make the axes with the pickable objects be the twined
> axes.
>

I'm using something on those lines since some time that works for me
since quite some time. Here is a code fragment:

            self.ax = self.fig.add_axes([.15, .15, .75, .75], label="left")
            self.ax2 = self.ax.twinx()
            self.ax2.set_label("right")
            # critical for picking!!!!
            self.ax2.set_zorder(0)
            self.ax2.set_autoscaley_on(True)
            self.ax.set_zorder(1)
            self.fig.sca(self.ax)

Best regards,

Armando

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users