3

I am trying to integrate matplotlib within a wxpython GUI, and I have gotten the interactive navigation toolbar to show up successfully. However, pressing any of the buttons does not change the plot, the plot only changes (based on the last pressed button) if you re-size the window or if you press another button (ie. zoom) and apply the relevant action (select a box/area). I tried looking online, but most of the answers either did not answer this specific issue, or the questions which seemed like they matched my query, were unanswered. Below is a segment of the relevant code:

Ignore all the numerous Update/Refresh calls, I was just trying to get the frame/plot to refresh, but it didn't work. Any ideas?

 class p1(wx.Panel):
        def __init__(self, parent):
            wx.Panel.__init__(self, parent, -1, size=(50,50))

            #Set up Figure
            self.figure = matplotlib.figure.Figure()
            self.canvas = FigureCanvas(self, -1, self.figure)

            #Set up Matplotlib Toolbar
            self.chart_toolbar = NavigationToolbar2Wx(self.canvas)
            tw,th = self.chart_toolbar.GetSizeTuple()
            fw,fh = self.canvas.GetSizeTuple()
            self.chart_toolbar.SetSize(wx.Size(fw, th))
            self.chart_toolbar.Realize()

            graphs_sizer = wx.BoxSizer(wx.VERTICAL)

            graphs_sizer.Add(self.canvas, 20, flag=wx.EXPAND, border=5)
            graphs_sizer.Add(self.chart_toolbar, 1, flag=wx.ALIGN_CENTER, border=5)

            self.SetSizer(graphs_sizer)
            self.chart_toolbar.update()
            self.canvas.Update()
            self.canvas.Refresh()
            self.Update()

        def plot(self):
            self.axes = self.figure.add_subplot(111)
            self.axes.plot(aggregatePlot,color='blue',alpha=0.6,lod=True)
       
            self.canvas.draw()
            self.canvas.Update()
            self.canvas.Refresh()

    class TestFrame(wx.Frame):
        def __init__(self, parent, title):
            wx.Frame.__init__(self, parent, title=title, size=(200,200))

            #Create Splitter Window and Add Left/Right Panels
            self.sp = wx.SplitterWindow(self)
            self.p1 = p1(self.sp)
            self.p2 = wx.Panel(self.sp, style=wx.SUNKEN_BORDER)
            self.sp.SplitVertically(self.p1, self.p2, 100)

            #Create Buttons
            self.siButton = wx.Button(self.p1, -1, "Si", size=(40,20), pos=(10,10))
            self.siButton.Bind(wx.EVT_BUTTON, self.Si)

            self.siButton = wx.Button(self.p2, -1, "No", size=(40,20), pos=(10,10))
            self.siButton.Bind(wx.EVT_BUTTON, self.No)

            #Create Status Bar
            self.statusbar = self.CreateStatusBar()
            self.statusbar.SetStatusText("Hola")

            #Plot
            self.p1.plot()

        #Event Handlers
        def Si(self, event):
            self.statusbar.SetStatusText("Si")

        def No(self, event):
            self.statusbar.SetStatusText("No")

    app = wx.App(redirect=False)
    frame = TestFrame(None, 'Hello World!')
    frame.Show(True)
    frame.p1.plot()
    frame.p1.canvas.Update()
    frame.p1.canvas.Refresh()
    app.MainLoop()

An example is shown below, the zoom button is pressed and a rectangular area for zoom is selected, but nothing happens. The zoom rectangle also has tons of little internal rectangles, but the actual graph doesn't change.

example of issue

3
  • I do not know what exactly you do expect: you are plotting exactly once, so why would you expect the plot to change (except for zooming/scaling)? Better said, you are plotting twice, but the second one frame.p1.plot() is a no-op, because aggregatePlot should not have changed. Commented Mar 3, 2015 at 8:02
  • Sorry maybe I didn't explain properly, an example of what I feel is wrong is that I click the zoom button, select a rectangular area to zoom into on the plot. Now from what I know of matplotlib, the plot should change to be that zoomed in area. Nothing actually happens right now. Now after that if I select pan and move a bit, or resize the entire plot, the graph changes to be where I zoomed in before, and then the pan action happens. Does that make sense? Commented Mar 3, 2015 at 17:41
  • Never mind, please see answer below, there was probably an issue with my matplotlib version, an update fixed it. Commented Mar 3, 2015 at 18:07

1 Answer 1

2

An update to matplotlib just fixed my issue, not sure what the problem was but I found a bug online similar to the issue I was facing and it seemed to be internal. I just used conda to update my version of matplotlib, by running:

conda update matplotlib

Thanks!

Sign up to request clarification or add additional context in comments.

3 Comments

Might I ask which version were you using, and which version are you on now? I have seen this issue, as well.
I don't exactly remember which version I was using, but I just checked the current version and it is 1.4.3 . Hopefully that helps!
Thanks. Yeah I was using 1.3 something and updated the other day to 1.4.3. Didn't think to check if this issue was resolved, and it seems that it has been. Thanks for posting this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.