FigureCanvasWxAgg not redrawn with wxpython 4.0.1 on Ubuntu 17.10

Riccardo Borgani <[email protected]> Wed, 7 Feb 2018 23:33:59 -0800 (PST)
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
Hi all,

I have a matplotlib figure embedded in a wx gui which needs to be redrawn 
periodically as new data comes in.
To do that, I first instantiate the class Figure from matplotlib.figure and 
the class FigureCanvasWxAgg from matplotlib.backends.backend_wxagg.

After creating the plot, a call to FigureCanvasWxAgg.draw() draws the plot.
The problem comes when I try to later update the plot: on Ubuntu 17.10 the 
plot simply does not update, although I get no error.


The sample program below reproduces the issue.
With wxpython 4.0.1, it works fine on macOS 10.12, Windows 10 and Ubuntu 
16.04, but fails on Ubuntu 17.10.
Fails means that the plot is not updated despite the calls to canvas.draw 
do not raise any error.
With wxpython 3.0.2.0, it works fine on every platform.


I suspect the might be an issue with the version of some library, so I also 
attach the output of the command "pip -v wheel wxpython --no-cache-dir", in 
case it helps debugging.
Python version 2.7.14
matplotlib version 2.1.2

Any idea what could be the issue? Should I call something else in addition 
to the draw method?
Thank for your help!

Riccardo

from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
import numpy as np
import wx


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        # Create figure and canvas
        self.fig = Figure()
        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)

        # Plot something
        self.t = np.linspace(0., 2. * np.pi, 1001)
        self.freq = 1.
        self.ax = self.fig.add_subplot(1, 1, 1)
        self.line, = self.ax.plot(self.t, np.sin(self.freq * self.t))
        self.canvas.draw()

        # Start a timer to update the plot
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
        self.timer.Start(1000)

    def on_timer(self, evt):
        # change plot data
        self.freq += 1.
        self.line.set_ydata(np.sin(self.freq * self.t))
        # print and update
        print("Freq: {:.0f}".format(self.freq))
        wx.CallAfter(self.canvas.draw)


wxapp = wx.App(redirect=False)
frame = MyFrame(None, wx.ID_ANY, "Test")
frame.Show()
wxapp.MainLoop()



-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
pip_log.zip (application/zip, 103.7 KB) - not displayed