Uzair
Uzair

Reputation: 473

VSCode 'default dark' theme doesn't automatically defaults the matplotlib style to 'dark_background'


Summary

When figure is drawn with matplotlib using VSCode Jupyter Notebook, the figure is rendered in light theme even when the VSCode theme is dark. By my understanding, this issue was resolved and the VSCode is supposed to default the matplotlib figures to dark_background when the VSCode theme is default dark.

What am I doing wrong?


I am fairly new to this whole data science and machine learning scene, and up till now I have been using Jupyter Notebook (and sometimes Jupyter Lab) for all my coding needs. However, the code completion in Jupyter Notebook leaves something to be desired, and so began my search for alternatives to Jupyter Notebook.

I recently discovered that VSCode supports the use of Jupyter Notebook natively and after installing python extension, I was able to create new and open previously saved .ipynb files and every thing works great (especially the IntelliSense).

There is, however, one issue which is somewhat a nuisance. My theme for VSCode is default dark, and the figures produced by matplotlib are in light theme.

using matplotlib in VSCode .ipynb

I know I can use following code to render the figures in dark mode:

from matplotlib import style
style.use('dark_background')

But on GitHub, this issue has already been addressed so that when the VSCode is in dark mode, then the VSCode will automatically default the matplotlib style to dark_background. However I am not experiencing this automation.

Is there some setting that I have failed to configure?

Upvotes: 6

Views: 6730

Answers (2)

mjspier
mjspier

Reputation: 6526

On macOS with VS version 1.63.2 I found that enabling the following setting did the trick:

enter image description here

Upvotes: 11

red-isso
red-isso

Reputation: 343

After some searching I found this solution: In settings (via ctrl+,) search for jupyter run startup commands

edit the json to:

    "jupyter.runStartupCommands": [
        "import matplotlib.pyplot as plt",
        "plt.style.use('dark_background')"
    ]

Then, restart your kernel.

Note, that somehow only using matplotlib.style.use('dark_background') does not yet fully work out, since some part gets overwritten on loading pyplot in the notebook it seems.

Upvotes: 6

Related Questions