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), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()
What happens is that a window appears for less than a second, and then disappears again.
Using the Pyzo IEP IDE (using same interpreter) on the same code the plot shows as expected.
...So the problem must be with some setting on Pycharm. I've tried using both python.exe and pythonw.exe as interpreter both with same results.
This is my sys_info:
C:\pyzo2014a\pythonw.exe -u C:\Program Files (x86)\JetBrains\PyCharm Community Edition 3.4.1\helpers\pydev\pydevconsole.py 57315 57316
PyDev console: using IPython 2.1.0import sys; print('Python %s on %s' % (sys.version, sys.platform))
Python 3.4.1 |Continuum Analytics, Inc.| (default, May 19 2014, 13:02:30) [MSC v.1600 64 bit (AMD64)] on win32
sys.path.extend(['C:\\Users\\Rasmus\\PycharmProjects\\untitled2'])
In[3]: import IPython
print(IPython.sys_info())
{'commit_hash': '681fd77',
'commit_source': 'installation',
'default_encoding': 'UTF-8',
'ipython_path': 'C:\\pyzo2014a\\lib\\site-packages\\IPython',
'ipython_version': '2.1.0',
'os_name': 'nt',
'platform': 'Windows-8-6.2.9200',
'sys_executable': 'C:\\pyzo2014a\\pythonw.exe',
'sys_platform': 'win32',
'sys_version': '3.4.1 |Continuum Analytics, Inc.| (default, May 19 2014, '
'13:02:30) [MSC v.1600 64 bit (AMD64)]'}
I had the same problem. Check wether
plt.isinteractive()
is True. Setting it to 'False' helped for me.Just add
plt.pyplot.show()
, that would be fine.The best solution is disabling SciView.
In my case, I wanted to do the following:
Following a mix of the solutions here, my solution was to add before that the following commands:
with the following two imports
It seems that all the commands are necessary in my case, with a MBP with ElCapitan and PyCharm 2016.2.3. Greetings!
For those who are running a script inside an IDE (and not working in an interactive environment such as a python console or a notebook), I found this to be the most intuitive and the simplest solution:
It shows the figure and waits until the user clicks on the new window. Only then it resume the script and run the rest of the code.
For beginners, you might also want to make sure you are running your script in the console, and not as regular Python code. It is fairly easy to highlight a piece of code and run it.