摆脱python matplotlib条形图中的灰色背景

use*_*827 3 python matplotlib

我如何摆脱下面的图中使用python matplotlib中的foll命令制作的灰色背景

ax.bar(x_axis,bar_val,yerr=err_val,linewidth=0,width=0.2)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

har*_*pan 7

set_axis_bgcolor功能在2.0版中已弃用。使用set_facecolor代替。您的代码为:

 ax.set_facecolor('white')
Run Code Online (Sandbox Code Playgroud)


cge*_*cge 5

首先,我应该指出,matplotlib的默认背景不是灰色。您是否在使用seaborn之类的东西(我认为不适当)在每次导入时都会默认混淆matplotlib的默认值?

因为我假设斧头已经是您的轴,所以您可以执行以下操作:

ax.set_axis_bgcolor('white')
Run Code Online (Sandbox Code Playgroud)

  • 美学是seaborn的首要目标。但如果您不想修改图形美学,则可以执行“import seaborn.apionly as sns”。 (3认同)