简体   繁体   中英

OSX How to bring Matplotlib window to the front?

I'm trying to use matplotlib for chart visualizations, but it is very annoying to look for a window each time I run the project. Is there any way to force it to be on top of other windows? I use OSX 10.8 and PyCharm IDE and already tried

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

Which fails with

AttributeError: 'FigureManagerMac' object has no attribute 'window'

I'd appreciate any other ideas.

This works for me from IPython:

from pylab import get_current_fig_manager
fm = get_current_fig_manager()
fm.show()

I haven't found a case in which show() doesn't work by itself, though.

you're call to window.raise_() is from PyQT. Indeed, you can raise the window in this way but you need to:

  • set PyQT4 as your backend before you do any other business with matplotlib

And

import matplotlib
matplotlib.use('Qt4Agg')
  • Either you fix you import statement (remove the brackets) or save yourself the import and access the window through the figure

with

window = fig.canvas.manager.window
  • Only then you can call window.raise_() and the window will be in front of pycharm.

[cphlewis] had a great answer. I found myself doing this so often that I def a little function to pop all my windows up to the surface:

def pop_all():
    #bring all the figures hiding in the background to the foreground
    all_figures=[manager.canvas.figure for manager in matplotlib.\
        _pylab_helpers.Gcf.get_all_fig_managers()]
    [fig.canvas.manager.show() for fig in all_figures]
    return len(all_figures)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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