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

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

VSCode 中的 Python:繪圖中的數(shù)據(jù)未更新

VSCode 中的 Python:繪圖中的數(shù)據(jù)未更新

翻翻過去那場雪 2022-10-05 18:33:52
我想在循環(huán)中繪制數(shù)據(jù)以喚起新數(shù)據(jù)的“實時更新”。但是我只得到了我的情節(jié)的一次更新,并且沒有其他數(shù)據(jù)被添加到情節(jié)中。我做錯了什么?import numpy as npimport matplotlib.pyplot as pltimport timefig=plt.figure()ax1=fig.add_subplot(1,1,1)x=[]y=[]for n in range(20):    x.append(n)    y.append(n*2)    ax1.clear()    ax1.scatter(x,y)    #fig.canvas.draw()    plt.autoscale(enable=True, axis='both')    plt.show()    time.sleep(0.1)
查看完整描述

1 回答

?
侃侃無極

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

你必須使用FuncAnimation。這將是您的示例的實現(xiàn) -


import numpy as np

import matplotlib.pyplot as plt

from matplotlib.animation import FuncAnimation

import time


fig=plt.figure()

ax1=fig.add_subplot(1,1,1)


x=list(range(20))

y=[n*2 for n in x]


def animate(i):

    ax1.clear()

    ax1.scatter(x[:i],y[:i])

    plt.autoscale(enable=True, axis='both')


ani = FuncAnimation(fig, animate, interval=100)

plt.show()

更新

為了處理無法在數(shù)組中預先計算的數(shù)據(jù),如上所示,您可以使用 FuncAnimation 的 frames 參數(shù),如下所示 -


import numpy as np

import matplotlib.pyplot as plt

from matplotlib.animation import FuncAnimation

import time


fig=plt.figure()

ax1=fig.add_subplot(1,1,1)


x=[]

y=[]


def frames():

    for i in range(20):

        yield i, i*2


def animate(args):

    ax1.clear()

    x.append(args[0])

    y.append(args[1])

    ax1.scatter(x, y)

    plt.autoscale(enable=True, axis='both')


ani = FuncAnimation(fig, animate, frames=frames, interval=100)

plt.show()


查看完整回答
反對 回復 2022-10-05
  • 1 回答
  • 0 關注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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