【发布时间】:2017-10-31 21:08:10
【问题描述】:
我有一个 python / matplotlib 应用程序,它经常使用来自测量仪器的新数据更新绘图。当用新数据更新绘图时,相对于我桌面上的其他窗口,绘图窗口不应从背景变为前景(反之亦然)。
这在运行带有 matplotlib 1.5.2rc 的 Ubuntu 16.10 的机器上使用 Python 3 可以正常工作。但是,在另一台装有 Ubuntu 17.04 和 matplotlib 2.0.0 的机器上,每次使用新数据更新绘图时,图形窗口都会弹出到前面。
如何在使用新数据更新绘图时控制窗口前景/背景行为并保持窗口焦点?
这是一个说明我的绘图例程的代码示例:
import matplotlib
import matplotlib.pyplot as plt
from time import time
from random import random
print ( matplotlib.__version__ )
# set up the figure
fig = plt.figure()
plt.xlabel('Time')
plt.ylabel('Value')
plt.ion()
# plot things while new data is generated:
t0 = time()
t = []
y = []
while True:
t.append( time()-t0 )
y.append( random() )
fig.clear()
plt.plot( t , y )
plt.pause(1)
【问题讨论】:
-
因为我无法以任何方式对此进行测试,只是建议尝试什么:而不是
plt.ion(),如果您使用plt.show(block=False)然后在您的while循环中添加plt.draw()会发生什么在plt.plot()通话之后? -
@Thomas Kühn:感谢您的建议。但是,这并没有改变 Ubuntu 17.04 / matplotlib 2.0.0 环境中的任何内容。
-
你在用什么backend?可能值得改变它,看看这是否能解决问题。
-
@Ed Smith:我不知道上面显示的示例代码默认使用哪个后端。但为了确保我明确选择了 TkAgg 后端进行了尝试。这并没有改变任何东西。
标签: python matplotlib background window focus