熊猫堆积条形图-更改堆积条的edgecolor

千K:

我可以将边缘设置作为一个应用于所有堆叠的条形吗?

这是一个例子:

df = pd.DataFrame([[2,5,7,11], [4,8,11,45]]).T
ax = df.plot.bar(stacked=True)
ax.containers[0][2].set_edgecolor('green')
ax.containers[0][2].set_linewidth(5)
ax.containers[1][2].set_edgecolor('green')
ax.containers[1][2].set_linewidth(5)

这给出了: 在此处输入图片说明

我想要的是绿色边缘围绕整个条形,而不会在堆叠的矩形之间断裂,有什么想法吗?

我想要一片T骨牛排 :

我不确定您是否可以指定不绘制每个矩形的边缘之一。因此,一种想法是Rectangle独立绘制一个图,并从中访问位置,高度和宽度ax.containers

from matplotlib.patches import Rectangle
df = pd.DataFrame([[2,5,7,11], [4,8,11,45]]).T
ax = df.plot.bar(stacked=True)
ax.add_patch(Rectangle(xy=ax.containers[0][2].get_xy(), 
                       width=ax.containers[0][2].get_width(),
                       height=ax.containers[0][2].get_height() 
                              +ax.containers[1][2].get_height(), 
                       fc='none', ec='green', linewidth=5)
            )

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章