3

I'm using PyCharm with Darcula theme and Jupyter notebook from anaconda package. I faced a problem that Darcula theme is inconvinient to use with Jupyter notebook

For example, pandas plot's axis is not readable.

I tried to find out, how to change notebook cell background, but looks like that there is no possibility to do that.

Of course, I can change PyCharm theme to another, but I used to work under this theme. And of course, I can change background of plot in code, but it is inconvinient to change background for each plots (for example, if I work with ready notebook)

Can I change cells background or the only way is to change theme to another?

Gcinbax
  • 187
  • 3
  • 12

4 Answers4

4

Probably a bit too late, but here is a solution for future reference:

1 - Go to PyCharm > Preferences and type in the search bar "Invert image outputs for dark themes"

2 - Go to Language & Frameworks > Jupyter and uncheck the "Invert image outputs for dark themes" box.

3 - Restart PyCharm for option to take effect.

mcs01
  • 51
  • 7
2

Per https://stackoverflow.com/a/40371037/2529760, you can use

fig = plt.figure()
fig.patch.set_facecolor('white')

or

plt.gca().patch.set_facecolor('white')

to force a white background beneath the axis labels on a per-plot basis. You can use

plt.rcParams['figure.facecolor'] = 'white'

to achieve this on a per-notebook basis.

To change this setting globally, normally you can edit the matplotlibrc file, but it appears Jupyter overrides this to some degree. Following https://nbviewer.jupyter.org/github/mgeier/python-audio/blob/master/plotting/matplotlib-inline-defaults.ipynb, you can create a file ipython_kernel_config.py at the correct location (~/.ipython/profile_default by default) containing the line

c.InlineBackend.rc = {'figure.facecolor': 'white'}

Any of these options will ensure the plot has a white background so the text is legible.

Demo image

Sam Van Kooten
  • 324
  • 1
  • 11
  • Unfortunately this answer no longer works as of the new Jupyter editor in PyCharm 2022. – RHS May 13 '22 at 08:07
1

You can try the seaborn package:

import seaborn as sns
sns.set_context('notebook')
sns.set_style('white')

It will change the output plot background to white.

CatchC
  • 71
  • 7
0

The temporary workaround for me is to explicitly call plt.show() at the end of cell.

Example

I am also looking for a better solution.

Xirui
  • 1
  • 1