6

I just got a new PC and downloaded visual studio code. I'm trying to run the exact same plots as the code I had on my other PC (just plt.plot(losses)) but now matplotlib seems to have a dark background instead of white:

enter image description here

I found this and this that had opposite problems. To clarify, I'm asking how to change the matplotlib background plots to white (note that in my other machine I didn't have to hard code any matplotlib background information so I think it's a visual studio problem, but couldn't figure it out)

Yulia V
  • 3,507
  • 10
  • 31
  • 64
Penguin
  • 1,923
  • 3
  • 21
  • 51
  • 1
    are you asking how to change the VS Code theme? – Paul H Dec 17 '21 at 20:33
  • Apologies for the confusion, please see my clarification – Penguin Dec 17 '21 at 20:36
  • https://matplotlib.org/stable/tutorials/introductory/customizing.html – Paul H Dec 17 '21 at 20:41
  • 1
    VS Code inject a color scheme onto matplotlib when using notebooks. The question is not "How can I change my matplotlib color", but "How can I stop VS code from interfering with my matplotlib colors", which none of the current answers touches. – Olsgaard Jan 19 '23 at 06:33

4 Answers4

7

You could also set the runtime configuration (rcParams) to change it for the entire sacript/notebook (documentation)

import matplotlib as mpl
mpl.rcParams['figure.facecolor'] = 'white'
Tobias P. G.
  • 827
  • 8
  • 15
6

Difficult to be sure since I cannot reproduce your problem.

Two things to try (both presume that you import matplotlib using import matplotlib.pyplot as plt):

  1. if you use plt.figure, add facecolor='white' parameter. Or try to run fig.set_facecolor('white') (fig here is the variable that stored the figure which facecolor you are changing. If you don't have any, use plt.gcf().set_facecolor('white') once the figure is created; gcf() returns current figure, see this doc).
  2. Try to change plt.style.context as in this matplotlib example.
Yulia V
  • 3,507
  • 10
  • 31
  • 64
  • 3
    Yea, the `style` worked. It's just weird because I didn't need to do anything using the exact same code in my other machine. So I think it's definitely a visual studio code issue. But alas, this will do. Thanks – Penguin Dec 17 '21 at 22:12
1

Jupyter: Theme Matplotlib Plots setting image

Changing this setting did the trick for me

theCrow
  • 176
  • 3
  • 13
1

in the settings-extensions-python-experiments: Opt Out Form-

there is and option that says:

jupyter.themeMatplotlibPlots": false,

if true mark it false this worked for me

Bbb
  • 13
  • 3