Blit: previous frames not cleared

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Blit: previous frames not cleared

Jonathan Dan
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


#!/usr/bin/python3

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)

    try:

        canvas.restore_region(background)

        line.set_ydata(y)

        ax.draw_artist(line)

        canvas.blit(ax.bbox)

    except AttributeError:

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

        canvas.draw()

        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)

canvas.set_size_request(400,400)

canvas.draw()

background = canvas.copy_from_bbox(ax.bbox)

main_window.add(canvas)

main_window.show_all()

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

Gtk.main()


Thank you
Jonathan
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Loading...