python中plot實現(xiàn)即時數(shù)據(jù)動態(tài)顯示方法
在Matlab使用Plot函數(shù)實現(xiàn)數(shù)據(jù)動態(tài)顯示方法總結(jié)中介紹了兩種實現(xiàn)即時數(shù)據(jù)動態(tài)顯示的方法??紤]到使用python的人群日益增多,再加上本人最近想使用python動態(tài)顯示即時的數(shù)據(jù),網(wǎng)上方法很少,固總結(jié)于此。
示例代碼1
import matplotlib.pyplot as plt import numpy as np import time from math import * plt.ion() #開啟interactive mode 成功的關(guān)鍵函數(shù) plt.figure(1) t = [0] t_now = 0 m = [sin(t_now)] for i in range(2000): t_now = i*0.1 t.append(t_now)#模擬數(shù)據(jù)增量流入 m.append(sin(t_now))#模擬數(shù)據(jù)增量流入 plt.plot(t,m,'-r') plt.draw()#注意此函數(shù)需要調(diào)用 time.sleep(0.01)

示例代碼2
上面的方式,可以在跳出的畫圖面板內(nèi)動態(tài)顯示,但是如果想在jupyter notebook中直接動態(tài)顯示,上面的方法將無效。因此,補上在jupyter notebook中可行的動態(tài)顯示示例程序。以供舉一反三之用。
這里寫代碼片
import math import random import numpy as np import matplotlib import matplotlib.pyplot as plt %matplotlib inline # set up matplotlib is_ipython = 'inline' in matplotlib.get_backend() if is_ipython: from IPython import display plt.ion() def plot_durations(y): plt.figure(2) plt.clf() plt.subplot(211) plt.plot(y[:,0]) plt.subplot(212) plt.plot(y[:,1]) plt.pause(0.001) # pause a bit so that plots are updated if is_ipython: display.clear_output(wait=True) display.display(plt.gcf()) x = np.linspace(-10,10,500) y = [] for i in range(len(x)): y1 = np.cos(i/(3*3.14)) y2 = np.sin(i/(3*3.14)) y.append(np.array([y1,y2])) plot_durations(np.array(y))

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python 中Arduino串口傳輸數(shù)據(jù)到電腦并保存至excel表格
這篇文章主要介紹了python Arduino串口傳輸數(shù)據(jù)到電腦并保存至excel表格,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-10-10
python之tensorflow手把手實例講解斑馬線識別實現(xiàn)
目前智慧城市的發(fā)展,人們生活處處有科技,比如人臉識別,智慧交通,無人駕駛等前沿的科技產(chǎn)品也都融入了人們生活中;本篇文章帶你從頭開始實現(xiàn)斑馬線識別2021-09-09
Python?中?Pandas?文件操作和讀取?CSV?參數(shù)詳解
CSV?又稱逗號分隔值文件,是一種簡單的文件格式,以特定的結(jié)構(gòu)來排列表格數(shù)據(jù),這篇文章主要介紹了Python?之?Pandas?文件操作和讀取?CSV?參數(shù)詳解,需要的朋友可以參考下2023-03-03
從DataFrame中提取出Series或DataFrame對象的方法
今天小編就為大家分享一篇從DataFrame中提取出Series或DataFrame對象的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11
Python處理文件的方法(mimetypes和chardet)
這篇文章主要介紹了Python處理文件的方法(mimetypes和chardet),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09

