简体   繁体   English

Matplotlib窗口出现在后面?

[英]Matplotlib window appears at the back?

Whenever I call show() in matplotlib the plot window appears behind all other windows and I have to minimize everything to see it. 每当我在matplotlib中调用show()时,绘图窗口就会出现在所有其他窗口后面,我必须尽量减少所有内容才能看到它。 Is there any way I can prevent this or programmatically bring it to the front. 有什么方法可以阻止这个或以编程方式将它带到前面。 On OSX Lion. 在OSX Lion上。 Python 2.7 Python 2.7

Not exactly an answer to your question, but I'm using ipython instead of the default python console. 不完全是你的问题的答案,但我使用ipython而不是默认的python控制台。 When launched it with ipython --pylab I can plot eg by typing 当使用ipython --pylab启动时,我可以通过输入来绘制

>> plot([1,3,2])

and have the plot pop up in front. 并在前面弹出情节。 It also has some other very nice features ;) 它还有一些非常好的功能;)

Matplotlib developer's seem to be aware of this issue. Matplotlib开发人员似乎意识到了这个问题。 But looking into https://github.com/matplotlib/matplotlib/issues/596 it looks like it's going to be a while until getting a solution, apparently because some people find it annoying that figure.show() "steals" screen space. 但是看看https://github.com/matplotlib/matplotlib/issues/596看起来好像它会有一段时间才能得到一个解决方案,显然是因为有些人觉得很烦人的数字。显示()“偷”屏幕空间。

Well. 好。 This answer is presented in the comments to the accepted answer but I think it deserves to have a place as a separate one as it solves the issue nicely. 这个答案在对已接受的答案的评论中提出,但我认为它应该有一个单独的地方,因为它很好地解决了这个问题。 Besides the author's problem I additionally had the problem that matplotlib window wasn't in the tray of active windows so I couldn't switch to it by <Alt>+<Tab> . 除了作者的问题,我还有问题,matplotlib窗口不在活动窗口的托盘中,所以我无法通过<Alt>+<Tab>切换到它。

Changing of the matplotlib's default backend macosx solved everything. 更改matplotlib的默认后端macosx解决了所有问题。 You can try immediately in your code like this: 你可以在你的代码中立即尝试这样:

import matplotlib
matplotlib.use("Qt5agg")

Qt5agg might not be presented in your system then please pick the one that is. Qt5agg可能不会出现在您的系统中,请选择那个。 You can find them: 你可以找到它们:

import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)

If it helped then you might want to change your backend in the configuration. 如果它有帮助,那么您可能希望在配置中更改后端。 For that locate it first: 为此,首先找到它:

import matplotlib
matplotlib.matplotlib_fname()

Then change backend: value: 然后改变backend:值:

backend      : macosx

to your backend. 到你的后端。 I used in the end: 我最后用过:

backend      : TkAgg

It may be OS-specific, but using interactive plotting (which plots as soon as you instruct) causes figures to come up in the foreground as soon as they're made on Ubuntu: 这可能是特定于操作系统,但使用交互式绘图(这只要您指示图)导致数据尽快拿出在前台,因为它们可以在Ubuntu上作出

import pylab as P
P.ion()
P.figure(1)
P.plot([1,2,3],[1,4,9])

I have the same set-up as nickponline. 我和nickponline有相同的设置。 What works for me is: 对我有用的是:

from pylab import get_current_fig_manager()
get_current_fig_manager().window.raise_()

If you have multiple figures, this only raises the currently active one. 如果您有多个数字,这只会提升当前活动的数字。 For that case, I found that the following works: 对于这种情况,我发现以下工作:

fig1=figure(1)
cfm1=get_current_fig_manager().window

fig2=figure(2)
cfm2=get_current_fig_manager().window
...
cfm1.activateWindow()
cfm1._raise()
pause(.1)  # or something else that uses up some time
cfm2.activateWindow()
cfm2.raise_()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM