2

I have the following plots embedded in a wxpython panel with a single x axis and 2 y axes.

            #Draw graph on 2nd panel
            self.p2.figure = matplotlib.pyplot.figure()
            self.p2.axes = self.p2.figure.add_subplot(111)
            self.p2.axes.plot(interval_graph_values,flow_graph_values,'b',linewidth=0.35)
            self.p2.axes.set_xlabel('Time after start of event (Hours)', fontsize=8, fontweight='bold')
            self.p2.axes.set_ylabel('Flow (cumecs)', fontsize=8, color = 'blue', fontweight='bold')
            for t1 in self.p2.axes.get_yticklabels():
                    t1.set_color('blue')
                    t1.set_fontsize(8)
            self.p2.axes.twinx()
            self.p2.axes.twinx().plot(interval_graph_values, rainfall_graph_values, 'r', linewidth=0.35)
            self.p2.axes.twinx().set_ylabel('Rainfall (mm)', fontsize=8, color='red', fontweight='bold')
            for t1 in self.p2.axes.twinx().get_yticklabels():
                    t1.set_color('red')
                    t1.set_fontsize(8)
            self.p2.canvas = FigureCanvas(self.p2, -1, self.p2.figure)
            #self.p2.toolbar = NavigationToolbar(self.p2.canvas)
            self.p2.sizer = wx.BoxSizer(wx.VERTICAL)
            self.p2.sizer.Add(self.p2.canvas, 1, wx.LEFT | wx.TOP | wx.GROW | wx.EXPAND)
            #self.p2.sizer.Add(self.p2.toolbar, 0, wx.EXPAND)
            self.p2.SetSizer(self.p2.sizer)
            self.p2.Fit()
            self.sp.SetMinimumPaneSize(360)

Data is pretty simple hydrometric stuff - interval_graph_values = [0.25, 0.5, 0.75...], flow_graph_values = [0.123, 0.191, 0.111...], rainfall_graph_values=[0, 0, 0.1...]

On mouse click events I want to retrieve event.ydata from the left hand axis, but I keep getting event data from the right axis instead.

I've tried playing with set_zorder() but that just seems to hide whichever axis has the lowest z_order value.

Is there a way of specifying which axis the mouse event should use?

*Sorry in advance if my code isn't the best, I'm trying to teach myself from scratch.

Thanks

Damien
  • 33
  • 4
  • Can you provide your code with a small example dataset? – Ffisegydd May 21 '14 at 20:44
  • Thanks. Code and dataset example added. – Damien May 21 '14 at 21:09
  • 2
    This is a know limitation. See https://github.com/matplotlib/matplotlib/pull/2986 for a patch to be able to swap the axes order. – tacaswell May 21 '14 at 23:02
  • 2
    See this question for a way to work around this: https://stackoverflow.com/questions/16672530/cursor-tracking-using-matplotlib-and-twinx/16672970#16672970 – tacaswell May 21 '14 at 23:06
  • Thanks, I had an inkling this might have been the case when the method wasn't apparent after a bit of digging around online. Thanks for the pointers to the work around too. – Damien May 22 '14 at 11:11

0 Answers0