資源簡(jiǎn)介
實(shí)時(shí)顯示數(shù)據(jù)對(duì)于數(shù)據(jù)采集,分析系統(tǒng)都是非常必要的。Python作為一種非常常用的語(yǔ)言,能夠在各種不同平臺(tái)上方便的使用。
在這個(gè)例子中,我使用簡(jiǎn)單的基礎(chǔ)函數(shù)實(shí)現(xiàn)數(shù)據(jù)的實(shí)時(shí)顯示。
代碼片段和文件信息
#!/usr/bin/env?python3
import?matplotlib.pyplot?as?plt
import?numpy?as?np
#?use?ggplot?style?for?more?sophisticated?visuals
plt.style.use(‘ggplot‘)
def?live_plotter(x_vecy_vec_dataline_realtimeidentifier=‘‘pause_time=0.1):
????if?line_realtime==[]:
????????#?this?is?the?call?to?matplotlib?that?allows?dynamic?plotting
????????plt.ion()
????????fig?=?plt.figure(figsize=(136))
????????ax?=?fig.add_subplot(111)
????????#?create?a?variable?for?the?line?so?we?can?later?update?it
????????line_realtime?=?ax.plot(x_vecy_vec_data‘-o‘a(chǎn)lpha=0.8)????????
????????#update?plot?label/title
????????plt.ylabel(‘Y?Label‘)
????????plt.title(‘title:?{}‘.format(identifier))
????????plt.show()
????
????#?after?the?figure?axis?and?line?are?created?we?only?need?to?update?the?y-data
????line_realtime.set_xdata(x_vec)
????line_realtime.set_ydata(y_vec_data)
????#?line_realtime.set_data(x_vecy
評(píng)論
共有 條評(píng)論