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.

enter image description here

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.

Asked By: Yu Gu

||

Answers:

try adding the line

import matplotlib.pyplot as plt

# Add this after you have done your plot
plt.show()
Answered By: Avi Thaker

For me, pressing double shift, selecting python scientific and deselecting "Show plots in tool window" worked.

Answered By: Abhinav

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

Answered By: user1796185

If you are receiving no error and you can not see your plot, check the items below:

  1. you have plt.show() at the very end.
  2. 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

Answered By: arsalan Yaghoubi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.