'VS Code Jupyter Notebook Graphs Display Transparently
I've recently downloaded VSCode and used it with Python and am having problems with the transparency of Matplotlib plots.
As you can see the, the figure element of the matplot graph is transparent, making the axes difficult to see.
Now when I go to look to other questions along similar lines it seems as though most people have the opposite problem ! For them, the white background appears when they don't want it too i.e the figure isn't being transparent. I tried using the approach outlined here - setting the default matplotlib style to white background - but this did not work.
This was a known problem back in 2019, but all the github threads on the issues declare it resolved. https://github.com/microsoft/vscode-jupyter/issues/2904
I am using the atom theme here (which has a different background colour), but the problem persists even when restarted using the default settings, making me think something else is afoot.
I am on a mac, using a python installation from anaconda.
Thanks!
Solution 1:[1]
It seems I hadn't installed the correct jupyter rendering package. Normally, this downloads alongside the base package (it seems I was given a mild slap by the hand of chance) but just installing it separately solved the problem.
https://github.com/microsoft/vscode-jupyter/issues/7470
(At the bottom)
Solution 2:[2]
I can't explain why vscode is doing this. However, the way I found to fix the issue is by explicitly setting the style context you want matplotlib to use in the plots.
import matplotlib.pyplot as plt
with plt.style.context('default'):
fig, ax = plt.subplots(...)
// your code in here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | asa |