Blit: previous frames not cleared

Hello I am trying to use the animation tools of matplotlib. When I
update the Axes some previous frames are not properly cleared. What am I
doing wrong? Here is a minimum working example


import gi

gi.require_version('Gtk', '3.0')

from gi.repository import Gtk, GLib

from matplotlib.figure import Figure

from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas

import numpy as np

# Update plot

def plot_update(ax, background, canvas, fig, line):

    global t

    t += 0.1

    x = np.linspace(t, 2*np.pi+t, 500)

    y = np.sin(x)






    except AttributeError:

        line, = ax.plot(y, animated=True)


        background = canvas.copy_from_bbox(ax.bbox)

    return True

main_window = Gtk.Window()

main_window.connect("delete-event", Gtk.main_quit)

# Initial data

t = 0

x = np.linspace(0, 2*np.pi, 500)

y = np.sin(x)

# Add figure to Window

fig = Figure(figsize=(5,5), dpi=96)

ax = fig.add_subplot(111)

line, = ax.plot(y, animated=True)

canvas = FigureCanvas(fig)



background = canvas.copy_from_bbox(ax.bbox)



GLib.timeout_add(200, plot_update, ax, background, canvas, fig, line)


Thank you