去掉 python matplotlib 条形图中的灰色背景

Get rid of grey background in python matplotlib bar chart

如何去除在 python matplotlib

中使用 foll 命令制作的下图中的灰色背景
ax.bar(x_axis,bar_val,yerr=err_val,linewidth=0,width=0.2)

首先,我应该指出灰色背景不是 matplotlib 的默认设置。您是否在使用 seaborn 之类的东西,它(在我看来是不恰当的)在您导入时默认会与 matplotlib 的默认值混淆?

因为我假设 ax 已经是你的轴,你可以这样做:

ax.set_axis_bgcolor('white')

set_axis_bgcolor 函数在 2.0 版中已弃用。请改用 set_facecolor。您的代码将是:

 ax.set_facecolor('white')