第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何更新matplotlib中的繪圖?

如何更新matplotlib中的繪圖?

梵蒂岡之花 2019-06-21 15:16:04
如何更新matplotlib中的繪圖?我在這里重畫這個數(shù)字有問題。我允許用戶在時間尺度(x軸)中指定單元,然后重新計算并調(diào)用此函數(shù)。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)
查看完整描述

3 回答

?
桃花長相依

TA貢獻1860條經(jīng)驗 獲得超8個贊

你基本上有兩個選擇:

  1. 做你目前正在做的事情,但是打電話graph1.clear()graph2.clear()在重新繪制數(shù)據(jù)之前。這是最慢、但最簡單、最健壯的選擇。

  2. 您可以只更新繪圖對象的數(shù)據(jù),而不是重新繪圖。您需要對代碼進行一些更改,但這比每次重新繪制代碼要快得多。但是,您正在繪制的數(shù)據(jù)的形狀不能更改,如果數(shù)據(jù)的范圍正在更改,則需要手動重置x和y軸限值。

為了給出第二種選擇的例子:

import matplotlib.pyplot as pltimport numpy as np

x = np.linspace(0, 6*np.pi, 100)y = np.sin(x)# You probably won't need this if you're embedding things in a tkinter plot...plt.ion()
fig = plt.figure()ax = fig.add_subplot(111)line1, = ax.plot(x, y, 'r-')
 # Returns a tuple of line objects, thus the commafor phase in np.linspace(0, 10*np.pi, 500):
    line1.set_ydata(np.sin(x + phase))
    fig.canvas.draw()
    fig.canvas.flush_events()


查看完整回答
反對 回復(fù) 2019-06-21
?
呼喚遠方

TA貢獻1856條經(jīng)驗 獲得超11個贊

您還可以這樣做:這將在圖上繪制一個10x1隨機矩陣數(shù)據(jù),用于for循環(huán)的50個循環(huán)。

import matplotlib.pyplot as pltimport numpy as np

plt.ion()for i in range(50):
    y = np.random.random([10,1])
    plt.plot(y)
    plt.draw()
    plt.pause(0.0001)
    plt.clf()


查看完整回答
反對 回復(fù) 2019-06-21
  • 3 回答
  • 0 關(guān)注
  • 2238 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號