Linux 防止matplotlib提高数字

Linux 防止matplotlib提高数字,linux,python-3.x,matplotlib,Linux,Python 3.x,Matplotlib,我最近升级到matplotlib 2.1.1(之前我使用的是1.5左右)。现在,matplotlib不断将图形窗口提升到前景。以前新创建的窗口也是如此(这很有意义),但现在,只要在脚本中调用pause(),窗口就会被带到前台 Python 3.6.5 (default, Apr 1 2018, 05:46:30) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information

我最近升级到matplotlib 2.1.1(之前我使用的是1.5左右)。现在,matplotlib不断将图形窗口提升到前景。以前新创建的窗口也是如此(这很有意义),但现在,只要在脚本中调用pause(),窗口就会被带到前台

Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.use('TkAgg')
>>> import matplotlib.pyplot as plt
>>> plt.figure()
<matplotlib.figure.Figure object at 0x7fab8c0ace80>
>>> plt.pause(1)  # <--- the figure gets created and put into foreground here (this is expected)
>>> plt.pause(1)  # <--- the figure gets put into foreground again here (this is undesired)
Python 3.6.5(默认,2018年4月1日05:46:30)
linux上的[GCC 7.3.0]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入matplotlib
>>>matplotlib.use('TkAgg')
>>>将matplotlib.pyplot作为plt导入
>>>plt.图()
>>>plt.pause(1)#>>plt.pause(1)#>>导入matplotlib
>>>matplotlib.use('Qt5Agg')
>>>将matplotlib.pyplot作为plt导入
>>>plt.图()

>>>plt.pause(1)#>>plt.pause(1)#>>plt.pause(1);plt.pause(1)#ngoldbaum发布的链接和源代码显示了问题。暂停现在被设计成总是提高所有数字。基于此,我能够创建一个解决方案,避免使用pause(),但允许我根据需要更新和暂停图形

需要两件事:

1) 需要显示每个新创建的图形。否则,窗口可能永远不会显示。因此,图形是使用命令创建的

figure = plt.figure()
figure.canvas.manager.show()
2) 实际上,每当我不暂停时,不带show()的pause()代码就会执行:

manager = matplotlib.backend_bases.Gcf.get_active()
if manager is not None:
    canvas = manager.canvas
    if canvas.figure.stale:
        canvas.draw_idle()
    canvas.start_event_loop(1)

这里,canvas.start\u event\u loop的参数是我们要暂停的持续时间。

我想你是在打ngoldbaum,你说得对。谢谢
manager = matplotlib.backend_bases.Gcf.get_active()
if manager is not None:
    canvas = manager.canvas
    if canvas.figure.stale:
        canvas.draw_idle()
    canvas.start_event_loop(1)