OSX How to bring the Matplotlib window to the fore?

I am trying to use matplotlib to render charts, but it is very annoying to look for a window every time I run a project. Is there a way to make it be on top of other windows? I am using OSX 10.8 and PyCharm IDE and have already tried

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

What fails with

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

I would appreciate any other ideas.

+4
source share
3 answers

This works for me with IPython:

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

I did not find a case where show () does not work on its own.

+1
source

you call window.raise_ () from PyQT. Indeed, you can raise the window this way, but you need:

  • set PyQT4 as a backend before doing any other operations with matplotlib

AND

 import matplotlib matplotlib.use('Qt4Agg') 
  • Either you correct the import statement (remove the brackets), or save the import and access the window through the shape

from

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

[cphlewis] got a great answer. I found myself doing this so often that I was doing a little function to open all my windows 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) 
+1
source

Source: https://habr.com/ru/post/1499528/


All Articles