在save.onclicked上,我想一次又一次地重绘图形/图,直到关闭matplotlib窗口。但是使用以下代码
我尝试在save_loc函数的末尾使用while循环,使用全局标志变量,但是结果没有什么不同。
while(plot[0]==1 and check==1):
callback = Index
save_loc = plt.axes([0.8,0.00,0.1,0.03])
save = Button(save_loc, 'Save Locations')
save.on_clicked(callback.save_locations)
plt.draw() #redraw
class Index:
def save_locations(self):
global count
count=count+1;
for i in range(nBus,maxVal):
x[0].append("")
x[1].append("")
x[2].append("")
x[3].append("")
x[4].append("")
x[5].append("")
kneePoints = lengths[2]
for i in range(kneePoints,maxVal):
x[16].append("")
x[17].append("")
x[18].append("")
extraPaths = lengths[3]
for i in range(extraPaths, maxVal):
x[19].append("")
x[20].append("")
nVol = lengths[4]
for i in range(nVol, maxVal):
x[21].append("")
x[22].append("")
for i in range(1,maxVal):
x[23].append("")
print(x)
p = list(zip(*x))
print("In save_loc function")
print(p)
csv_write_database(p)
z,maxVal2,pos,pos1,plot,colormap,labels,kneeEdges,kneeLabels,kneeDict,busDict,edge_label,edge_label1,edge_label2,n,e,lengths2 = read_csv_file()
nBus2 = lengths2[0]
plt.clf()
g = nx.Graph()
nx.draw_networkx(g,pos,node_size=120,nodelist=n[0],node_color=colormap['765kV'],with_label='false',aplha =0.2)
nx.draw_networkx(g,pos,node_size=120,nodelist=n[1],node_color=colormap['400kV'],with_label='false',aplha =0.2)
nx.draw_networkx(g,pos,node_size=120,nodelist=n[2],node_color=colormap['220kV'],with_label='false',aplha =0.2)
nx.draw_networkx(g,pos,node_size=120,nodelist=n[3],node_color=colormap['132kV'],with_label='false',aplha =0.2)
nx.draw_networkx(g,pos,node_size=120,nodelist=n[4],node_color=colormap['110kV'],with_label='false',aplha =0.2)
nx.draw_networkx(g,pos,node_size=120,nodelist=n[5],node_color=colormap['66kV'],with_label='false',aplha =0.2)
nx.draw_networkx(g,pos,node_size=120,nodelist=n[6],node_color=colormap['33kV'],with_label='false',aplha =0.2)
nx.draw_networkx_labels(g,pos,labels,font_size=8,aplha =0.2)
ax = fig.add_subplot(111)
drs.clear()
circles.clear()
for i in range(0,nBus2):
circles.append(patches.Circle((z[0][i],z[1][i]), 0.001,fc = 'g'))
for circ in circles:
ax.add_patch(circ)
dr = DragThePoint(circ)
dr.connect()
drs.append(dr)
print("COUNT : ",count)
callback2 = Index2
save_loc2 = plt.axes([0.8,0.00,0.1,0.03])
save2 = Button(save_loc2, 'Save Locations')
save2.on_clicked(callback2.save_locations2)
plt.draw() #redraw
while(plot[0]==1 and check==1):
callback = Index
save_loc = plt.axes([0.8,0.00,0.1,0.03])
save = Button(save_loc, 'Save Locations')
save.on_clicked(callback.save_locations)
plt.draw()