python - 如何每秒更新python中的图表
问题描述
我正在尝试使用 matplotlib.animation 每秒更新一次时间序列数据。这将用于从多个通道获取数据。但是,当我在 update() 函数中使用动画时,没有达到间隔时间(函数循环更快)。请帮助我澄清如何以更适当的方式调用更新函数。谢谢。
大多数示例显示从函数外部调用 update()。然而,在这种情况下,一次更新多个频道成为一个问题。
def update(self,start): x = np.random.normal(size=1) y = np.random.normal(size=1) deneme=self.graphicsView.plot(x,y,pen=None,symbol='+') time.sleep(0.2) animation.FuncAnimation(self.graphicsView,ui.update(),interval =1000)
解决方案
试试看:
from datetime import time
second = datetime.now().strftime("%S")
while True:
do some things your code should do (no time.sleep in there)
second_before = datetime.now().strftime("%S")
if second != second_before:
second = second_before
call the function
推荐阅读
- android - 无法安装 SDK 工具,完成按钮被禁用
- git - 如何修复 git 错误:RPC 失败;HTTP 520 卷曲 22?
- powershell - 导出 CSV 文件的格式与实际命令不同
- discord.py - 当我们不是服务器的所有者时,我们如何添加机器人?
- css - CSS卡片按钮:悬停为整张卡片添加填充/边距(我认为)
- google-sheets - 希望为我的 dnd 组添加一个按钮(谷歌表格)
- css - 从 npm 花费太多时间来安装 Chakra UI
- go - reading golang websocket returns random bytes
- python - 在python中打印格式文本
- ruby-on-rails - 为什么我不能使用 ActionController::Parameters 的 keys() 函数?