From: Stephan M. <zw...@we...> - 2011-02-10 15:45:28
|
Right now I use a customized FigureCanvasTkAgg and overwrite the draw() and resize() methods to reset the z-order of the axes before drawing / resizing the figure and to restore the desired z-order afterwards. This works quite well but it would be nice to have the picking work like in version <=0.99.3. ----------------------- 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) ax0 = f.add_subplot(111) ax1 = ax0.twinx() t = arange(0.0,3.0,0.01) s1 = sin(2*pi*t) s2 = 2*cos(2*pi*t) ax0.plot(t,s1,color='red', picker=True) ax1.plot(t,s2,picker=True) ax0.my_zorder=0 ax1.my_zorder=0.1 class MyFigureCanvasTkAgg(FigureCanvasTkAgg): def draw(self): ax0 = self.figure.axes[0] ax1 = self.figure.axes[1] ax0.set_zorder(0) ax1.set_zorder(0) FigureCanvasTkAgg.draw(self) ax0.set_zorder(ax0.my_zorder) ax1.set_zorder(ax1.my_zorder) def resize(self, event): ax0 = self.figure.axes[0] ax1 = self.figure.axes[1] ax0.set_zorder(0) ax1.set_zorder(0) FigureCanvasTkAgg.resize(self, event) ax0.set_zorder(ax0.my_zorder) ax1.set_zorder(ax1.my_zorder) 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 ax0.my_zorder == 0: ax0.my_zorder=0.1 ax1.my_zorder=0 else: ax0.my_zorder=0 ax1.my_zorder=0.1 ax0.set_zorder(ax0.my_zorder) ax1.set_zorder(ax1.my_zorder) canvas = MyFigureCanvasTkAgg(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() ----------------------- -- 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-tp25049128p30893570.html Sent from the matplotlib - users mailing list archive at Nabble.com. |