我在这里重新绘制数字时遇到问题.我允许用户在时间刻度(x轴)中指定单位,然后重新计算并调用此函数plots()
.我希望情节简单地更新,而不是在图中附加另一个情节.
def plots():
global vlgaBuffSorted
cntr()
result = collections.defaultdict(list)
for d in vlgaBuffSorted:
result[d['event']].append(d)
result_list = result.values()
f = Figure()
graph1 = f.add_subplot(211)
graph2 = f.add_subplot(212,sharex=graph1)
for item in result_list:
tL = []
vgsL = []
vdsL = []
isubL = []
for dict in item:
tL.append(dict['time'])
vgsL.append(dict['vgs'])
vdsL.append(dict['vds'])
isubL.append(dict['isub'])
graph1.plot(tL,vdsL,'bo',label='a')
graph1.plot(tL,vgsL,'rp',label='b')
graph2.plot(tL,isubL,'b-',label='c')
plotCanvas = FigureCanvasTkAgg(f, pltFrame)
toolbar = NavigationToolbar2TkAgg(plotCanvas, pltFrame)
toolbar.pack(side=BOTTOM)
plotCanvas.get_tk_widget().pack(side=TOP)
Run Code Online (Sandbox Code Playgroud) 我正在循环绘制并保存数千个文件以供以后的动画使用,如下所示:
import matplotlib.pyplot as plt
for result in results:
plt.figure()
plt.plot(result) # this changes
plt.xlabel('xlabel') # this doesn't change
plt.ylabel('ylabel') # this doesn't change
plt.title('title') # this changes
plt.ylim([0,1]) # this doesn't change
plt.grid(True) # this doesn't change
plt.savefig(location, bbox_inches=0) # this changes
Run Code Online (Sandbox Code Playgroud)
当我运行它并获得大量结果时,它会在保存数千个图后崩溃。我想我想做的是重用我的轴,就像这个答案一样: https: //stackoverflow.com/a/11688881/354979,但我不明白如何。我该如何优化它?