Hello!

I am also using two axes in a plot and want to be able to pick the lines of
both axes.
So far I used MPL 0.99.3 and a button on my interface to change the z-order
of the axes in order to be able to pick lines of the "active" axes and to
see the correct x/y data in the navigation toolbar. The callback code of my
button is basically the code from othererik.

Since MPL 1.0.0 I have the problem that lines of the second axes simply
disappear from the plot whenever the plot is redrawn and it's zorder is
higher.

Here is my example code:
http://old.nabble.com/file/p30717629/twinxtest.py twinxtest.py 
-----------------------
import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi, cos
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import Tkinter as Tk


root = Tk.Tk()

f = Figure(figsize=(5,4), dpi=100)
ax1 = f.add_subplot(111)
ax2 = ax1.twinx()

t = arange(0.0,3.0,0.01)
s1 = sin(2*pi*t)
s2 = 2*cos(2*pi*t)

ax1.plot(t,s1,color='red', picker=True)
ax2.plot(t,s2,picker=True)


def pick_cb(event):
    if event.artist.get_lw() > 1:
        event.artist.set_lw(1)
    else:
        event.artist.set_lw(3)
    f.canvas.draw()
    

def toggle():
    if ax1.get_zorder() == 0:
        ax1.set_zorder(0.1)
        ax2.set_zorder(0)
    else:
        ax1.set_zorder(0)
        ax2.set_zorder(0.1)


canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

canvas.mpl_connect('pick_event', pick_cb)

button = Tk.Button(master=root, text='Toggle', command=toggle)
button.pack(side=Tk.BOTTOM)

Tk.mainloop()
------------------

Right after start I can only pick the blue line and both lines are properly
shown even when I resize the plot. When I hit the "Toggle" button now I can
pick the red line but the pick event callback also calls canvas.draw() which
let's the blue line disappear. When I click "Toggle" and call canvas.draw()
again by resizing the window, the blue line is visible again.
In Matplotlib 0.99.3 everything worked as I expected with this code. Both
lines were always visible.

-Stephan

-- 
View this message in context: 
http://old.nabble.com/onpick-on-a-2-y-plot-%28-via-twinx%28%29-%29-seems-to-only-allow-picking-of-second-axes%27s-artists-tp25049128p30717629.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to