栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

实时可视化数据-流式数据可视化 python

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

实时可视化数据-流式数据可视化 python

ion版
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure()
ax1 = fig.add_subplot(111)
t = []
v = []
line, = ax1.plot(t, v, linestyle="-", color="r")
import numpy as np
ys = np.random.normal(100, 10, 1000)

for i in range(2000):
    t.append(i)
    v.append(ys[i])
    ax1.set_xlim(min(t), max(t) + 1)
    ax1.set_ylim(min(v), max(v) + 1)
    line.set_data(t, v)
    plt.pause(0.001)
    ax1.figure.canvas.draw()
animation版
# _*_ coding:utf-8 _*_

import time
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

import numpy as np
x1 = np.arange(0, 20, 1)
y1 = np.random.normal(100, 10, 20)

print(x1.shape)
print(y1.shape)
# format the time style 2016-12-01 00:00:00

x = []
y = []
# initial the size of the figure
fig = plt.figure(figsize=(18, 8), facecolor="white")
# fig.subplots_adjust(left=0.06, right=0.70)
ax1 = fig.add_subplot(111)

# initial plot
p1, = ax1.plot(x, y, linestyle="dashed", color="red")

ax1.set_ylabel("value")

def stream(i):
    x.append(x1[i])
    y.append(y1[i])
    time.sleep(3)#可以执行其他程序,比如等待,删除这个操作也可以
    # update the axis
    ax1.set_xlim(min(x1), max(x1)+1)
    ax1.set_ylim(min(y1), max(y1)+1)

    p1.set_data(x, y)
    ax1.figure.canvas.draw()
    return p1


# main animated function
# for i in range(25):#可以将下面实现放在循环里面
anim = FuncAnimation(fig, stream, frames=len(x1))
plt.show()

参考:可视化篇:流式数据监控(python)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/341690.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号