使用Python将图形/轮廓添加到绘图中

时间:2018-01-23 13:13:37

标签: python plot frame outline

我正在使用

创建一个条形图
ax = lasso_output_df2.plot(kind='bar', title ="Spain Coefficient Variables [alpha_10]", figsize=(15, 10),  legend=False,  fontsize=12)
ax.set_xticklabels(lasso_output_df2.Features)
ax.set_axis_bgcolor('white')

使用pandas创建df。

如何在实际图表中添加框架或轮廓?

我试过以下内容:

edgecolor = 'black'

frameon=False

ax.spines['top'].set_visible(True)

ax.spine_color('black')

当前情节。 enter image description here

渴望的情节。 enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用matplotlib.rcParams自定义当前matplotlib样式。只需在创建绘图之前添加以下代码,然后所有后续绘图都将应用更新。

import matplotlib as mpl
mpl.rcParams.update(**{u'axes.spines.bottom': False,
      u'axes.spines.left': False,
      u'axes.spines.right': False,
      u'axes.spines.top': False})

这将立即更新所有四个方面。如果您只想更改一侧,可以简单地将值设置为:

mpl.rcParams['axes.spines.left'] = False