使用黑色iPython Notebook配置文件显示Seaborn / Matplotlib绘图的最佳方式

时间:2014-08-22 16:10:10

标签: matplotlib ipython ipython-notebook seaborn

我使用了奇妙的Seaborn库来获取IPython Notebook中的一些摘要统计信息。我最近切换到我的笔记本的深色主题,并试图找出深色背景的Seaborn最佳见解。我正在使用darkgrid样式,但传说仍然是黑色打印,这使得它们无法阅读。这是一个例子:

Seaborn on dark background

修复我使用Seaborn的样式以使图例显示为白色的最佳方法是什么?

更新: 我刚注意到我的Matplotlib图表存在同样的问题..所以我的问题更为笼统。您使用什么样式来允许黑暗图上的白色,以便传说可读?

4 个答案:

答案 0 :(得分:14)

您可以自定义seaborn样式,并尝试使其相对容易。

如果要查看被视为“样式”定义一部分的每个参数,只需调用不带参数的sns.axes_style(),它将返回当前设置。从0.3.1开始,对于默认样式(“darkgrid”),它看起来像这样:

{'axes.axisbelow': True,
 'axes.edgecolor': 'white',
 'axes.facecolor': '#EAEAF2',
 'axes.grid': True,
 'axes.labelcolor': '.15',
 'axes.linewidth': 0,
 'font.family': 'Arial',
 'grid.color': 'white',
 'grid.linestyle': '-',
 'image.cmap': 'Greys',
 'legend.frameon': False,
 'legend.numpoints': 1,
 'legend.scatterpoints': 1,
 'lines.solid_capstyle': 'round',
 'pdf.fonttype': 42,
 'text.color': '.15',
 'xtick.color': '.15',
 'xtick.direction': 'out',
 'xtick.major.size': 0,
 'xtick.minor.size': 0,
 'ytick.color': '.15',
 'ytick.direction': 'out',
 'ytick.major.size': 0,
 'ytick.minor.size': 0}

一个好的启发式方法是,您可能只需要名称中包含"color"的参数,因此您可以对其进行过滤:

{k: v for k, v in sns.axes_style().items() if "color" in k}

返回

{'axes.edgecolor': 'white',
 'axes.facecolor': '#EAEAF2',
 'axes.labelcolor': '.15',
 'grid.color': 'white',
 'text.color': '.15',
 'xtick.color': '.15',
 'ytick.color': '.15'}

然后,您可以将包含这些参数值的自定义词典传递到sns.set_style()

custom_style = {'axes.labelcolor': 'white',
                'xtick.color': 'white',
                'ytick.color': 'white'}
sns.set_style("darkgrid", rc=custom_style)

答案 1 :(得分:5)

sns.set_style("darkgrid")

将背景设为白色,以便您可以看到文字。

enter image description here

答案 2 :(得分:1)

我发现添加了这个

plt.figure(facecolor='w')

每次我的情节照顾轴背景。

答案 3 :(得分:1)

为什么不简单

plt.style.use("dark_background")