1

I am using Anaconda with Python 2.7 in the Spyder environment. When plotting a pyplot, the window hides behind all my other open windows instead of appear in front. How would I make the figure appear in front of all other open windows?

The matplotlib backend is: Qt4Agg

The Guy
  • 658
  • 1
  • 7
  • 21
  • I'd love that too, but as far as I've read, this is a pyplot thing and can't be altered much. But I'd love to be shown otherwise... – Roberto Apr 12 '15 at 17:04
  • That depends on the pyplot/matplotlib backend you use; could you add that to your question? (`import matplotlib; matplotlib.get_backend()` tells you which.) Most have a function for this; but if all else fails, you can always use the [PyWin32](http://stackoverflow.com/a/1025331/1881610) module and call [SetForegroundWindow](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx) on the plot window. – Phillip Apr 13 '15 at 06:44
  • I am using Qt4Agg as the backend. – The Guy Apr 13 '15 at 19:37
  • Possible duplicate: [how to make a pyqt window jump to the front](http://stackoverflow.com/questions/12118939/how-to-make-a-pyqt4-window-jump-to-the-front). – Roland Smith Apr 14 '15 at 20:04

2 Answers2

4

(Spyder dev here) The only backend that have this functionality is the TkAgg one. The code posted by @valentin in his/her answer should work when using that backend.

All other backends miss this possibility. This has been a known limitation of Matplotlib for quite some time, as can be seen in this Github issue.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124
3

You can try something like:

fig = plt.figure()
plt.show()

fig.canvas.manager.window.activateWindow()
fig.canvas.manager.window.raise_()

But the desired behaviour is backend dependent. On tkinter:

fm = plt.get_current_fig_manager() 
#bring to front
fm.window.attributes('-topmost', 1)
#allow other windows to cover
fm.window.attributes('-topmost', 0)
valentin
  • 3,498
  • 15
  • 23
  • The first method did indeed work for me on Mac OS with Python3.5 & SpyderPrefs set to `Qt4Agg`. Spyder 2.3.8, Python **3.5.1** 64bits, Qt 4.8.7, PyQt4 (API v2) 4.11.4 on Darwin – Demis May 24 '16 at 23:00