PyCharm not displaying Matplotlib plot
Question:
My program works fine when I view it in scientific mode, but I found that I cannot edit the plot in scientific mode, while I remember I can do that when the plot is displayed in a separate window. So I just disable the Python Scientific -> Show plots in tool window
, then my program still runs with no error, but no figure is displayed.
Because it can be displayed normally for the scientific mode, I don’t think this is the problem of my program. It must be some setting for my PyCharm that went wrong. I have looked for the answers but most of those answers only address the problem of incorrect backend, apparently not applicable to my scenario.
I actually think PyCharm scientific view is more of a hindrance than a help. It reduces the original functionality for editing the plot and only leaves it with a rastered version of the plots.
In Scientific view it totally reduces the option to adjust the plot, while when I tried to disable the scientific view, nothing was displayed. This is quite annoying.
Answers:
try adding the line
import matplotlib.pyplot as plt
# Add this after you have done your plot
plt.show()
For me, pressing double shift, selecting python scientific and deselecting "Show plots in tool window
" worked.
try alternative matplotlib backends eg
import matplotlib.pyplot as plt
matplotlib.use('TkAgg') or
matplotlib.use('Qt5Agg')
Then turn interactive mode on in IDE by:
plt.ion() # required for non notebook code from matplotlib .ioff() to turn off
then it should open the window with the plot rendered, PyCharm then pushes it to the background:
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()
Worked for me
PyCharm:
PyCharm 2021.1.1 (Community Edition)
Build #PC-211.7142.13, built on April 21, 2021
Runtime version: 11.0.10+9-b1341.41 amd64
VM: Dynamic Code Evolution 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1972M
Cores: 12
Registry: debugger.watches.in.variables=false
Non-Bundled Plugins: String Manipulation (8.15.203.000.3), com.jetbrains.plugins.ini4idea (211.6693.44), izhangzhihao.rainbow.brackets (6.17), com.leinardi.pycharm.pylint (0.12.2), com.kite.intellij (1.9.3)
Python 3.8.10
Anaconda Nov 2020 – build x64 windows
If you are receiving no error and you can not see your plot, check the items below:
- you have
plt.show()
at the very end.
- On the top right side of the pycharm IDE click on SciView and then click on plots. Sometimes your plot doesn’t appear on the screen but is kept there.
Good Luck
My program works fine when I view it in scientific mode, but I found that I cannot edit the plot in scientific mode, while I remember I can do that when the plot is displayed in a separate window. So I just disable the Python Scientific -> Show plots in tool window
, then my program still runs with no error, but no figure is displayed.
Because it can be displayed normally for the scientific mode, I don’t think this is the problem of my program. It must be some setting for my PyCharm that went wrong. I have looked for the answers but most of those answers only address the problem of incorrect backend, apparently not applicable to my scenario.
I actually think PyCharm scientific view is more of a hindrance than a help. It reduces the original functionality for editing the plot and only leaves it with a rastered version of the plots.
In Scientific view it totally reduces the option to adjust the plot, while when I tried to disable the scientific view, nothing was displayed. This is quite annoying.
try adding the line
import matplotlib.pyplot as plt
# Add this after you have done your plot
plt.show()
For me, pressing double shift, selecting python scientific and deselecting "Show plots in tool window
" worked.
try alternative matplotlib backends eg
import matplotlib.pyplot as plt
matplotlib.use('TkAgg') or
matplotlib.use('Qt5Agg')
Then turn interactive mode on in IDE by:
plt.ion() # required for non notebook code from matplotlib .ioff() to turn off
then it should open the window with the plot rendered, PyCharm then pushes it to the background:
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()
Worked for me
PyCharm:
PyCharm 2021.1.1 (Community Edition)
Build #PC-211.7142.13, built on April 21, 2021
Runtime version: 11.0.10+9-b1341.41 amd64
VM: Dynamic Code Evolution 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1972M
Cores: 12
Registry: debugger.watches.in.variables=false
Non-Bundled Plugins: String Manipulation (8.15.203.000.3), com.jetbrains.plugins.ini4idea (211.6693.44), izhangzhihao.rainbow.brackets (6.17), com.leinardi.pycharm.pylint (0.12.2), com.kite.intellij (1.9.3)
Python 3.8.10
Anaconda Nov 2020 – build x64 windows
If you are receiving no error and you can not see your plot, check the items below:
- you have
plt.show()
at the very end. - On the top right side of the pycharm IDE click on SciView and then click on plots. Sometimes your plot doesn’t appear on the screen but is kept there.
Good Luck