Pycharm jupyter细胞背景

问题描述 投票:2回答:3

我正在使用带有Darcula主题的PyCharm和来自anaconda包的Jupyter笔记本。我遇到了一个问题,Darcula的主题不适合与Jupyter笔记本一起使用

例如,pandas plot的轴不可读。

我试图找出,如何改变笔记本电脑的背景,但看起来没有可能做到这一点。

当然,我可以将PyCharm主题改为另一个,但我曾经在这个主题下工作。当然,我可以在代码中更改绘图的背景,但是更改每个绘图的背景是不方便的(例如,如果我使用现成的笔记本)

我可以更改单元格背景或唯一的方法是将主题更改为另一个吗?

python pycharm jupyter-notebook
3个回答
1
投票

你可以试试seaborn包:

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

它会将输出图背景更改为白色。


0
投票

我的临时解决方法是在单元格的末尾显式调用plt.show()

我也在寻找更好的解决方案。


0
投票

根据https://stackoverflow.com/a/40371037/2529760,你可以使用

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

要么

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

在每个图表的基础上强制轴标签下方的白色背景。您可以使用

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

以每个笔记本为基础实现这一目标。

要全局更改此设置,通常可以编辑matplotlibrc文件,但看起来Jupyter会在某种程度上覆盖它。在https://nbviewer.jupyter.org/github/mgeier/python-audio/blob/master/plotting/matplotlib-inline-defaults.ipynb之后,您可以在包含该行的正确位置(默认为ipython_kernel_config.py)创建文件~/.ipython/profile_default

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

任何这些选项都将确保绘图具有白色背景,因此文本清晰可辨。

Demo image

© www.soinside.com 2019 - 2024. All rights reserved.