python學習之使用Matplotlib畫實時的動態(tài)折線圖的示例代碼
有時,為了方便看數據的變化情況,需要畫一個動態(tài)圖來看整體的變化情況。主要就是用Matplotlib庫。
首先,說明plot函數的說明。
plt.plot(x,y,format_string,**kwargs)
x是x軸數據,y是y軸數據。x與y維度一定要對應。
format_string控制曲線的格式字串
下面詳細說明:
- color(c):線條顏色
- linestyle(ls):線條樣式
- linewidth(lw):線的粗細
關于標記的一些參數:
- marker:標記樣式
- markeredgecolor(mec):標記邊緣顏色
- markeredgewidth(mew):標記邊緣寬度
- markerfacecolor(mfc):標記中心顏色
- markersize(ms):標記大小
另外,marker關鍵字參數可以和color以及l(fā)inestyle這兩個關鍵字參數合并為一個字符串。
例如:‘ro-'表示紅色的直線,標記為圓形
線條color顏色:
線條樣式(linestyle):
標記(marker)參數:
程序demo如下:
得到的結果是循環(huán)的sin(x)的折線圖
''' 動態(tài)折線圖演示示例 ''' import numpy as np import matplotlib.pyplot as plt plt.ion() plt.figure(1) t_list = [] result_list = [] t = 0 while True: if t >= 10 * np.pi: plt.clf() t = 0 t_list.clear() result_list.clear() else: t += np.pi / 4 t_list.append(t) result_list.append(np.sin(t)) plt.plot(t_list, result_list,c='r',ls='-', marker='o', mec='b',mfc='w') ## 保存歷史數據 #plt.plot(t, np.sin(t), 'o') plt.pause(0.1)
得到的結果如下:
到此這篇關于python學習之使用Matplotlib畫實時的動態(tài)折線圖的示例代碼的文章就介紹到這了,更多相關Matplotlib 實時動態(tài)折線圖內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
參考博客鏈接:https://blog.csdn.net/zhanghao3389/article/details/82685072
https://blog.csdn.net/u013468614/article/details/58689735
到此這篇關于python學習之使用Matplotlib畫實時的動態(tài)折線圖的示例代碼的文章就介紹到這了,更多相關Matplotlib 實時動態(tài)折線圖內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Expected conditions模塊使用方法匯總代碼解析
這篇文章主要介紹了Expected conditions模塊使用方法匯總代碼解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-08-08