matplotlib中的交互模式 [英] Interactive mode in matplotlib

查看:107
本文介绍了matplotlib中的交互模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据从套接字连接接收到的 y 轴数据动态更新散点图.我在交互模式下使用 python matplot lib 来执行此操作,但是在动态更新期间,如果我将窗口移动到不同的位置或最小化窗口,则绘图更新会突然停止.该怎么做?

我已附加了此处使用的示例动态更新代码,并且这里也出现了相同的问题.

 将matplotlib.pyplot导入为plt随机导入导入时间项目 = [25.5,26.7,23.4,22.5,20,13.4,15.6,-12,-16,20]x = [1,2,3,4,5,6,7,8,9,10]plt.ion()#互动对于范围内的 i (1,100):plt.title('graph plotting')plt.ylabel('温度')plt.xlabel('时间')random.shuffle(项目)plt.plot(x,items,'ob-')plt.axis([0,10,-40,40])plt.draw()#time.sleep(2)plt.clf()plt.close()

解决方案

此处是带有PyQt的版本./p>

I want to dynamically update the scatter plot based on the y-axis data received from a socket connection. I used python matplot lib in interactive mode to do this, but during dynamic updation if i move the window to a different location or minimize the window then the plot updation stops abruptly. How to do this?

I have attached a sample dynamic updation code used here and the same problem appears here also.

import matplotlib.pyplot as plt
import random
import time
items = [25.5,26.7,23.4,22.5,20,13.4,15.6,-12,-16,20]
x = [1,2,3,4,5,6,7,8,9,10]

plt.ion() #  Interactive on

for i in range(1,100):
    plt.title('graph plotting')
    plt.ylabel('temperature') 
    plt.xlabel('time')
    random.shuffle(items)
    plt.plot(x,items,'ob-')
    plt.axis([0, 10, -40, 40])
    plt.draw()
    #time.sleep(2)
    plt.clf()
    plt.close()

解决方案

This page contains a couple of examples of dynamic plots with matplotlib and wxPython. And here is a version with PyQt.

这篇关于matplotlib中的交互模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆