Pycharm does not show plot from the following code:
import pandas as pd
import numpy as np
import matplotlib as plt
ts = pd.Series(np.random.randn(1000), in
Just use
plt.show()
This command tells the system to draw the plot in Pycharm.
Example:
plt.imshow(img.reshape((28, 28)))
plt.show()
Comment from DanT fixed this for me, matplotlib with pycharm on linux with the GTKagg backend. Upon importing matplotlib I would get the following error:
>>> import matplotlib as mpl
Backend GTKAgg is interactive backend. Turning interactive mode on.
Failed to enable GUI event loop integration for 'gtk'
When plotting something like so:
from matplotlib import pyplot as plt
plt.figure()
plt.plot(1,2)
plt.show()
A figure screen would pop up but no charts appear. using:
plt.show(block=True)
displays the graphic correctly.
I test in my version of Pycharm (Community Edition 2017.2.2), you may need to announce both plt.interactive(False) and plt.show(block=True) as following:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 6.28, 100)
plt.plot(x, x**0.5, label='square root')
plt.plot(x, np.sin(x), label='sinc')
plt.xlabel('x label')
plt.ylabel('y label')
plt.title("test plot")
plt.legend()
plt.show(block=True)
plt.interactive(False)
My env: macOS & anaconda3
This works for me:
matplotlib.use('macosx')
or interactive mode:
matplotlib.use('TkAgg')
I was able to get a combination of some of the other suggestions here working for me, but only while toggling the plt.interactive(False)
to True
and back again.
plt.interactive(True)
plt.pyplot.show()
This will flash up the my plots. Then setting to False
allowed for viewing.
plt.interactive(False)
plt.pyplot.show()
As noted also my program would not exit until all the windows were closed. Here are some details on my current run environment:
Python version 2.7.6
Anaconda 1.9.2 (x86_64)
(default, Jan 10 2014, 11:23:15)
[GCC 4.0.1 (Apple Inc. build 5493)]
Pandas version: 0.13.1
None of the above worked for me but the following did:
Disable the checkbox (Show plots in tool window) in pycharm settings > Tools > Python Scientific
.
I received the error No PyQt5 module found
. Went ahead with the installation of PyQt5
using :
sudo apt-get install python3-pyqt5
Beware that for some only first step is enough and works.