我已经从一组这样的图像制作了动画(10张快照):
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
import time
infile = open ('out.txt')
frame_counter = 0
N_p = 100
N_step = 10
N_line = N_p*N_step
for s in xrange(N_step):
x, y = [], []
for i in xrange(N_p):
data = infile.readline()
raw = data.split()
x.append(float(raw[0]))
y.append(float(raw[1]))
xnp = np.array(x)
ynp = np.array(y)
fig = plt.figure(0)
ax = fig.add_subplot(111, aspect='equal')
for x, y in zip(xnp, ynp):
cir = Circle(xy = (x, y), radius = 1)
cir.set_facecolor('red')
ax.add_artist(cir)
cir.set_clip_box(ax.bbox)
ax.set_xlim(-10, 150)
ax.set_ylim(-10, 150)
fig.savefig("step.%04d.png" % frame_counter)
ax.remove()
frame_counter +=1
现在,我想为每个显示时间步长的图像添加一个图例.
为此,我必须为这10张图像分别设置图例.问题是我已经测试了不同的东西,例如ax.set_label,cir.set_label等.
我得到这样的错误:
UserWarning: No labelled objects found. Use label='...' kwarg on individual plots
根据这个错误,我必须在各个图上添加标签,但是由于这是一个艺术家图,所以我不知道该怎么做.