vscode setup question - python plot background color - visual-studio-code

At some point, python plot color (either using jupyter notebook or ipython #%% command) is synced with my vscode theme. It wasn't before that the plot had white background as default.
When I use darker theme (monokai or vscode dark theme), the plot background become black. However, when I change it to light theme, the default python color comes back (white background). I need white background as default. I can set plot color for every script but it's very nuisance when I run other person's code, especially during collaborative works.
Which setting in vscode should I deal with? I tried several options related to jupyter, but they didn't solve my problem.
If the setting related to ipython, how can I check the setup?

The behavior you are describing is likely due to the matplotlib library, which is used for creating plots in Python. Matplotlib uses the default style for your system, which can be influenced by the theme you are using in your text editor.
To set the default style for matplotlib, you can use the following code at the beginning of your script:
import matplotlib as mpl
mpl.rcParams['figure.facecolor'] = 'white'
This will set the default background color of your plots to white, regardless of the theme you are using in your text editor.
If the rcParams setting is not being retained even after you set it, it could be because the settings are being overridden by a configuration file or by the settings in your IPython or Jupyter environment.
One way to ensure that your settings are retained is to create a custom matplotlib style file and set it as the default style. To do this, you can create a file called my_custom_style.mplstyle in a directory of your choice and include the following line in the file:
figure.facecolor : white
This sets the background color of the plots to white.
Then you can use this style by calling
mpl.style.use('my_custom_style')
This will set the default background color of your plots to white, regardless of the theme you are using in your text editor.
If you use jupyter notebook, you can also set the matplotlib style in the notebook by adding the following code snippet in the first cell of your notebook:
from matplotlib import style
style.use("<path-to-style-file>")
If you are using IPython, you can set the default matplotlib style by adding the following lines in your ipython_config.py file:
c.InteractiveShellApp.matplotlib = '<path-to-style-file>'
You can also check in ipython profile directory, if there any custom configuration files like ipython_kernel_config.py, ipython_config.py that might be overwriting your settings.

Related

Change jupyter notebook markdown font color in vscode

I am using VScode with a dark theme and the text dispayed in Jupyter notebook markdown is pretty pale example
What I have been doing is trying to change my color theme in settings.json, but I can not find a variable that accounts for the notebook markup font color, let me give you an example of an existing variable that is similar to what I am looking for "notebook.markup.fontSize": 20. I could not find neither the variable nor the full list of such.
I know I might explicitly assing font color for each cell, but I find it really tedious as I have tons of them.
Are there any other solutions to this problem?
I have tried installing extensions, checking out jupyter VScode settings. Couldn't find anything.

Visual Studio Code Jupyter Notebook matplotlib WIDGETS OUTPUT CELL background colour change [duplicate]

If I use a dark theme in Visual Studio Code and in Matplotlib, the figure can be configured to have dark background, but the background of the widget / cell is still white.
%matplotlib widget
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('dark_background')
figure, axis = plt.subplots()
axis.plot(np.arange(100))
This also happens if I use the option of the Jupyter extension to use the Visual Studio Code theme in the notebook (actually, then it's even worse because the axis labels are not visible).
Note, that I need to use %matplotlib widget as a renderer, and cannot use %matplotlib inline. For inline, I found a configuration that works.
In the browser, it works if I select the Jupyter dark theme, so I guess, I would kind of select a different "theme" in the Jupyter renderer extension, if something like this is possible (?)
Is there a way to configure the Jupyter extension / Visual Studio Code / ... to have a real "dark mode for Matplotlib"?
I have found a workaround!
(Make sure Visual Studio Code is closed.)
Open file explorer, go to:
C:\Users\<your_username_here>\.vscode\extensions\ms-toolsai.jupyter-<(THE VERSION NUMBER MAY VARY)2022.4.1021342353>\out\webviews\webview-side\ipywidgetsRenderer
Open the ipywidgetsRenderer.js file (using Notepad++ or Notepad or even Visual Studio Code) before letting any Jupyter stuff run
Wherever you see cell-output-ipywidget-background followed by background: white, replace white with black.
Now the problem is solved. Enjoy :)

How to change cell background colour of a VSCode Jupyter Notebook?

I would like to know what is the JSON setting to change the background colour of a VSCode Jupyter Notebook cell.
I found the VSCode Theme colour reference but I can't find the specific setting to do so.
I found the perfect colour theme but I would like to tweak the background colour cell just a bit.
For those interested the setting is:
"editorWidget.background": "#ff0000",
To find it, from the command palette I ran:
Developer: Generate Color Theme from Current Settings
This will create a new json document with ALL the elements currently affected by your current theme, from there I search for all the occurrences of the hex colour until I found the matching setting.
UPDATE: Please see Mark's answer below
Mark's answer is not comprehensive enough. Not sure if it is the best, please try.
In the settings.json -- can be found at File(Windows)/Code(Mac)>Preferences>Settings
Adding this into the json will work -- notebook's setting has to be put under the workbench.colorCustomizations.
"workbench.colorCustomizations": {
"notebook.cellEditorBackground": "#FFFFFF",
},
The rest of the settings you may follow Mark's guide above.
However, customizing the color background alone at jupyter notebook at vscode is not enough, i need the complete best settings including the font colors. Please share if you found the settings for all under notebook. Or can we change the notebook theme only but leaving the rest of vscode theme untouched?
vscode v1.59 is adding this colorCustomization:
"notebook.cellEditorBackground"
Also available:
"notebook.cellBorderColor"
Previously:
That theme color reference link doesn't seem to be kept up-to-date. See vscode Theme Color reference instead. There are a lot of notebook-related theme colors:
Notebook colors
including:
notebook.focusedCellBackground
notebook.selectedCellBackground
and many more.

Change the color of input cell in jupyter in vscode

I am using VSCode with Jupyter (for .ipynb files) and I would like to change the color of my input cells.
Currently, it looks like this :
How can I change the color of my input cell without changing the theme I use ? Thanks.
Go to settings and mark Python > Data Science: Ignore Vscode Theme, then restart VScode, after which Notebooks will become white. Not beautiful, but at least you now can see the input cells without kissing the display:
Same as #tyrex answer, except that now it is under the "Jupyter" extension. Found it by searching for "vscode theme" in the settings.

How do you change the color of commands entered at the terminal in Visual Studio Code?

I want to change the color of input commands at the terminal in VS Code. It seems that the default color used by all themes is terminal.ansiBrightYellow, which is #b5ba00. The only way I see to change it is to change the value of that color in settings:
Uncommenting the change to terminal.ansiBrightYellow effectively changes the color of the command:
This demonstrates that somewhere VS Code is setting the color of text entered at the terminal to terminal.ansiBrightYellow. Where can I find and how can I change that setting?
Note that this is different from the terminal.foreground setting, which doesn't affect user-entered text.
I'm on Windows using PowerShell, but I'm not sure that makes any difference.