天天看點

python怎麼用matplotlib_Python-如何在matplotlib中更新圖?

我在這裡重新繪制圖形時遇到問題。我允許使用者在時間刻度(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)