gpt4 book ai didi

python - matplotlib 中的交互模式

转载 作者:太空狗 更新时间:2023-10-29 21:53:46 25 4
gpt4 key购买 nike

我想根据从套接字连接接收到的 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()

最佳答案

This page包含几个使用 matplotlib 和 wxPython 进行动态绘图的示例。和 here是带有 PyQt 的版本。

关于python - matplotlib 中的交互模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1940387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com