我只是想在我的情节中添加一个暂停子句,我可以在其中自愿暂停实时流。这就是我正在尝试的。这是经过编辑的代码。它正在制作两个子图:散点图和饼图。我可以暂停散点图,但是当我暂停时饼图消失了。
def onClick(event):
global pause
pause ^= True
fig = plt.figure()
fig.canvas.mpl_connect('button_press_event', onClick)
plt.show()
while t<ran2:
if not pause:
ax = fig.add_subplot(2,1,1)
ay = fig.add_subplot(2,1,2)
mdfmt = md.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(mdfmt)
cmap=cm.jet
g=s[t:t+4]
h=[]
for i in g:
if i == 'Match':
h.append(1)
else:
h.append(0)
ax.scatter(x[t:t+4],y[t:t+4],c=h,s=150,marker='<',edgecolor='None', cmap = cm.jet)
ax.set_xlabel('Time')
ax.set_ylabel('Action')
mindate = min(data_mat['Date'].ix[t:t+4])
ax.set_title('Alarm System for site SPFD02 on date %s'%mindate)
yt=[-1,0,1]
ax.set_yticks(yt)
ax.set_yticklabels(('Closed','Not Ack','Assigned'))
ax.set_xlim(x[t],x[t+4])
# for pie chart
l = 'Match','No-Match'
colors = ['red','blue']
j = s[t:t+4].count('Match')
z = z + j
k = s[t:t+4].count('No-Match')
r = r + k
sizes = [z,r]
ay.pie(sizes,labels = l, colors = colors, autopct='%1.1f%%', shadow=True, startangle=140)
ay.set_aspect('equal')
t=t+1
else:
print 'paused'
plt.pause(0.1)
plt.cla()