python学习之使用Matplotlib画实时的动态折线图的示例代码
作者:象驮着的云 时间:2021-03-03 17:33:31
有时,为了方便看数据的变化情况,需要画一个动态图来看整体的变化情况。主要就是用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以及linestyle这两个关键字参数合并为一个字符串。
例如:‘ro-'表示红色的直线,标记为圆形
线条color颜色:
线条样式(linestyle):
标记(marker)参数:
程序demo如下:
得到的结果是循环的sin(x)的折线图
'''
动态折线图演示示例
'''
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)
得到的结果如下:
参考博客链接:https://blog.csdn.net/zhanghao3389/article/details/82685072
https://blog.csdn.net/u013468614/article/details/58689735
来源:https://blog.csdn.net/weixin_37552816/article/details/89555200
标签:Matplotlib,实时,动态折线图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一文带你掌握Python中多线程和线程池的使用方法
2022-10-20 21:53:09
Python算法中的时间复杂度问题
2021-03-20 04:52:50
![](https://img.aspxhome.com/file/2023/3/78573_0s.jpg)
服务器端控件是如何操作的?
2009-11-01 15:22:00
基于Python log 的正确打开方式
2021-05-29 21:42:59
设计师如何更有效拿到结果?
2008-09-22 20:30:00
![](https://img.aspxhome.com/file/UploadPic/20089/22/2008922203620332s.jpg)
python使用matplotlib绘图时图例显示问题的解决
2022-11-13 16:59:47
![](https://img.aspxhome.com/file/2023/8/62898_0s.jpg)
由 IE8 User-Agent 更新想到的
2009-01-12 18:33:00
一文带你吃透什么是PHP中的序列化
2023-06-12 19:44:20
详解django自定义中间件处理
2023-09-30 08:19:12
Python lxml模块安装教程
2021-08-26 22:23:43
仿淘宝星级评分效果
2010-09-03 18:37:00
pygame多种方式实现屏保操作(自动切换、鼠标切换、键盘切换)
2022-12-08 20:39:49
![](https://img.aspxhome.com/file/2023/7/95187_0s.gif)
python爬虫 urllib模块url编码处理详解
2021-09-13 02:24:37
详解AJAX核心 —— XMLHttpRequest 对象
2010-03-31 14:49:00
使用python turtle画高达
2021-11-05 20:47:48
![](https://img.aspxhome.com/file/2023/2/84082_0s.jpg)
python 双循环遍历list 变量判断代码
2021-02-10 12:38:12
手把手带你了解python多进程,多线程
2021-07-16 02:08:42
![](https://img.aspxhome.com/file/2023/6/95446_0s.png)
关于Python 常用获取元素 Driver 总结
2022-12-24 05:03:28
PHP数据类型之布尔型的介绍
2023-11-14 21:56:00
Django中select_related和prefetch_related的用法与区别详解
2023-10-08 12:38:08
![](https://img.aspxhome.com/file/2023/9/99409_0s.jpg)