在matplotlib中的交互模式

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

我附上了这里使用的示例动态更新代码,同样的问题也出现在这里。

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()

这个页面包含了一些matplotlib和wxPython动态图的例子。 这里是PyQt的一个版本。


为此,您需要有一个用于事件处理的主循环,以及您自己的事件处理程序,以在窗口调整大小或刷新时重绘图。

你会在网上或教程中找到许多关于此的例子。

我认为这最好通过使用UI工具包(例如wxPython)来处理,而不是使用matplotlib交互模式。 我过去也有类似的问题,并得到了一些很好的答案。

链接地址: http://www.djcxy.com/p/43741.html

上一篇: Interactive mode in matplotlib

下一篇: Why does the static analyzer warn of a garbage value in this code?