保存图形时Jupyter-notebook非透明绘图环境

Jupyter-notebook non-transparent plot surroundings when saving figure

我正在使用 jupyter-lab 绘制数据框。

fig = df.plot().get_figure()
fig.savefig("test.png")

不幸的是,绘图的周围(不在x和y轴之间的space)显示坐标的地方是透明的,即灰黑色方格图案,这使得坐标几乎不可读。有什么方法可以加宽非透明区域,以便包含坐标?

您可以通过多种方式实现此目的:

更新 matplotlib rcParams:

import matplotlib as mpl

mpl.rcParams.update({"figure.facecolor": "white"})

这将影响您在此脚本中设置此参数后的所有绘图。


为单个图形设置图形颜色:

fig = df.plot().get_figure()
fig.set_facecolor("white")