Hi -
I am wondering how to animate using blit and patches.
The code below was modified from one of the examples.
You will see that it shows (and moves) the rectangle just fine, but
the circle never shows up.
best,
Jaron
import gtk, gobject
import matplotlib
matplotlib.use('GTKAgg') #Agg rendering to a GTK canvas (requires PyGTK)
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from matplotlib.patches import CirclePolygon
fig = plt.figure(figsize=(14,10))
ax = fig.add_subplot(111, autoscale_on=False )
canvas = fig.canvas
x_start = array([1.0, 2, 2, 1, 1])
y_start = array([1.0, 1, 2, 2, 1])
plt.axis([-1, 7, -0.5, 2.2])
def update_line():
global x, y
print update_line.cnt
if update_line.background is None:
update_line.background = canvas.copy_from_bbox(ax.bbox)
canvas.restore_region(update_line.background)
x = x_start + 0.012 * update_line.cnt
y = y_start + 0.0001 * update_line.cnt
line, = ax.plot(x, y, animated=True, lw=2)
ax.draw_artist(line)
x_cir = 1.0 + 0.001*update_line.cnt
cir = CirclePolygon((x_cir, 1), 0.3, animated=True, resolution=6, lw=2
)
ax.draw_artist(cir)
canvas.blit(ax.bbox)
if update_line.cnt == 10000:
gtk.mainquit()
raise SystemExit
update_line.cnt += 1
return True
update_line.cnt = 0
update_line.background = None
def start_anim(event):
gobject.idle_add(update_line)
canvas.mpl_disconnect(start_anim.cid)
start_anim.cid = canvas.mpl_connect('draw_event', start_anim)
plt.show()