I'm experiencing an issue while using VS Code to debug Python files. It seems that since last updating VS Code matplotlib figures have stopped being displayed after calls of plt.show()
. There are no errors reported, and the script continues to execute as though the call had been successful, so I'm not sure what the cause is.
Initially I thought it was perhaps something to do with the backend, so I tried running in various Python environments with different matplotlib.plot
backends and Python versions but no success.
My only though is that it's possible VS Code settings are overriding the backend or environment somehow and might be causing this behaviour?
The issue actually stems from the matplotlib backend not being properly set, or from a missing dependency when compiling and installing matplotlib.
Install matplotlib by entering its name into the search field and then selecting the Run command: pip install matplotlib option. Running the command will install matplotlib , and any packages it depends on (in this case that includes numpy ). Choose the Packages tab. Consent to elevation if prompted to do so.
Occasionally, problems with Matplotlib can be solved with a clean installation of the package. In order to fully remove an installed Matplotlib: Delete the caches from your Matplotlib configuration directory. Delete any Matplotlib directories or eggs from your installation directory.
I was facing the same problem inside an Anaconda's virtual environment. I created a simple script (below), when running on Ubuntu's Terminal the plot appeared, but on VSCode's Terminal the plot didn't open and the script finished.
import matplotlib.pyplot as plt
plt.plot([1,2,3], [10, 20, 30])
plt.show()
I solved by opening VSCode Settings (JSON) and changing "terminal.integrated.inheritEnv" to true. I guess you should add this option if it's not there.
Found the solution on other answer: https://stackoverflow.com/a/63368392/2014507 (credits to Jiang)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With