Matplotlib doesn't show plots in new window

Hi All,

Setup: Ubuntu 18.04, Pycharm 2019.2 pro, python 3.6.8, matplotlib 3.1.1

I remember that when I used to plot figures on the latest version of pycharm 2018 the new figure would pop up a new window with the plotted figure. Only if `plt.show()` is typed the figure will be shown in sciview. 

How can I change it to act like the old version and to pop up a new window? I saw a similar problem with matplotlib installed by Anaconda (it's not my case I didn't use Anaconda to install it).

 

****** Edited *******

I just tried to unmark the "show plots in tool window" in the settings and even with using `plt.show()` nothing appeared (tried both with plt.show and without)

**********************

 

BR,

Aviv Shamsian

12 comments
Comment actions Permalink

You can try different matplotlib backends (backends are switched in the code and you can find it in matplotlib documentation).

For example matplotlib.use('TkAgg') should show plots in a separate window.

0
Comment actions Permalink

Got the following error while trying to use what you suggested:

From what I remember tkinteris natively installed as part of matplotlib or python, What should I do from here. And again before installing the pro 2019.2 version, I didn't face this error.

 

0
Comment actions Permalink

Ok, please remove the matplotlib.use and try to run your script from the terminal outside of IDE. Do you get plot shown in a pop up?

0
Comment actions Permalink

Hi Andrey,

Sorry for the late response I tried to reinstall (after uninstall) matplotlib but I got the following error:

I have uninstalled and installed the packege using the project interpreter menu under settings.

0
Comment actions Permalink

I think I know where the problem is coming from. when using the native project interpreter and checking the python version in the terminal by typing `python -V` the output is 'python 2.7.15+' even though it seems like using python 3.6 (showing in the menu). When I use the project's venv I can see it uses python 3.6.8.

Is there any way to make the native interpreter use the 3.6.8 version? The main reason I'm using the native interpreter is avoiding the installation of the packages each time I start new project.

 

 

BR,

Aviv Shamsian

0
Comment actions Permalink

Update - Ok it didn't work as well the Tkinter error still appears.

When running the script from terminalI get the same error using the 'TkAgg' backend. 

When I use the default backend I get a warning that the current backend doesn't support GUI so it can't show the figure.

the script:

import matplotlib.pyplot as plt
plt.plot([i for i in range(10)])
plt.show()

and also tried:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
plt.plot([i for i in range(10)])
plt.show()
0
Comment actions Permalink

This is the point of interest I think:

>When I use the default backend I get a warning that the current backend doesn't support GUI so it can't show the figure.

So there's something wrong with matplotlib you have installed for the current interpreter. I suggest figuring out first how to make it work from the terminal, then it should also work in PyCharm. But since it's unrelated to PyCharm, I suggest asking on another forum. www.stackoverflow.com might be a good help.

Or, you can just start up a new clean venv and install a new matplotlib there. Activate this venv in the terminal and try to plot something. In my case there's no issues - I get a GUI pop up with a plot.

Then try adding this new venv as new interpreter in PyCharm, and try to plot something. Don't forget to disable "Show plots in tool window" in SciView settings.

0
Comment actions Permalink

Hi Andrey,

Thank you for helping me.

If I start a new venv and install matplotlib it works fine the problem starts when I assign the main interpreter instead of the new one which I created. 

How can I use the main root interpreter without facing this error?

0
Comment actions Permalink

I just want to add something else when I use tkagg a popup window won't show sometimes but when it does you can't see the GUI info on the bottom of the window (like you can't see the location of the cursor etc.)

 

0
Comment actions Permalink

Hi Andrey,

How are you?

I need your help I created the following script:

If I run it through the terminal the good old GUI pops up but If I run it on Pycharm I can't see the plot not even at sciView, I don't want to see it on sciView the pop up GUI is the most convinient for me (but even on sciView you can't see it).

Please help me it's annoying!

0
Comment actions Permalink

Hi,

Do you have Settings | Tools | Python Scientific | Show plots in tool window option enabled? Are you certain you're not using Anaconda as the project interpreter?

 

Please try the following list of matplotlib backends: Qt5Agg, Qt4Agg and TkAgg

0
Comment actions Permalink

I was able to sort it out. Thank you Andrey for your help :)

0

Please sign in to leave a comment.