Have Pyplot windows appear as topmost window in Windows 7 - python

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

(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.

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)

Related

plt.show() from matplotlib does not open a window

I know this question or a related one has been asked many times, but I still have not found a solution: I ssh -X into a linux machine, where I run a conda installation of ipython. After importing matplotlib, I generate a plot (e.g., plt.plot(1,1)) and I want to show the plot in a window, which is forwarded to my local machine with plt.show(). This used to work, but suddenly no longer does: plt.show() does nothing. I guess this is related to a conda update, which I did yesterday, since a conda list --revisions does not show any suspicious recent changes in my environment.
From similar posts, I guess this is related to the matplotlib backend. The default backend 'Agg' generates png's via plt.savefig, but does not produce a plot in its own window, in which I can zoom. I have not managed to change the backend, though:
In [7]: import tkinter
In [8]: import matplotlib
In [9]: matplotlib.use('TkAgg')
In [10]: import matplotlib.pyplot as plt
gives
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
I have tried various similar things but with no success. Any suggestions?
Thank you!

Using PyCharm I want to show plot extra figure windows

After installing Anaconda3 & PyCharm in new PC, I tried to test the same code as uploaded here
And I got a window like this.
But usually I use the plot window like this format (from google image search)
I think the first view is useful for checking all of the plots, but I'm already used to the second version, separated plot figure from PyCharm console, and I can use the control panel.
So I want to use PyCharm as in the second picture. How can I change my PyCharm settings to use the second version plot figure (extra window)?
That's because PyCharm is opening it in Sciview. Go to Settings => search for Python Scientific. Uncheck the (only) box Show plots in toolwindows. Restart PyCharm. It should work like a charm ;)
Related to my answer here.
According to this, you can manually change the backend to fix the issue:
matplotlib.use('Qt5Agg')
Credit to #ImportanceOfBeingErnest for digging up the thread.
You need first to check if you have Pycharm Community or Pycharm Professional.
You can plot in different windows just in case you have a professional version.
You can use seeting -> scientific python ( link : https://www.jetbrains.com/help/pycharm/matplotlib-support.html ).
Or, use matplotlib backends: Qt5Agg, Qt4Agg and TkAgg.
(https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004382380-Matplotlib-doesn-t-show-plots-in-new-window )
However, I can suggest you to download your plot in a file and close the window. So, you can have your plots in different windows.
Check out this code:
file = '___your path___'
... make your code for visualisation
plt.show()
plt.savefig(file+'\\fig.png')
plt.close('all')
I was having the same problem, and not resolving it by only switching off scientific mode. Just press Cmd + Shift + A or Ctrl + Shift + A and search python scientific, then click on it and deselect show plots in tool window, you should be all set now.

Matplotlib doesn't show plots on Mac; plt.show() hangs on 'MacOSX' backend

As of late, I can't get my Matplotlib plots to show up. I have a very simple script:
import matplotlib.pyplot as plt
plt.plot([1,2,3])
but nothing ever shows up. If I include the line
plt.show()
then my Python process hangs.
In my ~/.config/matplotlib/matplotlibrc file I have
backend : MacOSX
interactive : True
I'm a little embarrassed to ask this question. I've been a Matplotlib user for many years and have never had this problem. I don't know where to begin to fix this problem. Help!
I'm using Matplotlib 2.0.0 with Python 3.5.2 from Anaconda.
The answer, as pointed out by #ImportanceOfBeingErnest is that the backend configuration for me wasn't working. I'm not sure if I need to install some additional libraries or not. I decided not to use the MacOSX backend and used the Qt5Agg backend. This worked just fine and I didn't have to install any new libraries.
I've just remove the line
interactive: True
enter code here
from my ~/matplotlib/matplotlibrc. It works fine with only backend: MacOSX using the plt.show() command.

Python Graphing on linux system without xserver

I am new to python and trying to explore graphs, could you please help me understand if I can plot graphs on the console using matplotlib on a linux system that has no XSERVER running?
Thanks.
You can use matplotlib with no X server by setting the backend to Agg, PS, PDF or SVG, Cairo or GDK (depending on what kind of file you wish to create). You can set the backend in your matplotlibrc file, which, depending on your installation, may be in a directory such as ~/ or ~/.matplotlib or ~/.config/matplotlib/.
Alternatively, you can set the backend in the script itself.
Be sure to set the backend first, before importing other modules such as pyplot:
import matplotlib
matplotlib.use("Agg")
See this SO question for examples.

Matplotlib drawings not shown as non-root user

Knowing that this is a question, 100times asked, but no solution helps me.
Trying to make a simple plot:
import matplotlib.pyplot as p
p.plot(range(20), range(20))
p.show()
I used several backends in ~/.matplotlib/matplotlibrc, such as GTK, GTKAgg, Qt4Agg, gdk, agg, svg, kairo,...), by adding the line
backend: <backend>
But nothing happens when I try to plot. No error message, simply nothing. I used both the standard console python2.7 and the IPython console.
I'm using CentOS with Gnome Desktop. Matplotlib is 1.2.0.
Do you have any ideas?
NOTE: I realized that it is a problem only as non-root user.

Categories

Resources