我可以将边缘设置作为一个应用于所有堆叠的条形吗?
这是一个例子:
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)
我想要的是绿色边缘围绕整个条形,而不会在堆叠的矩形之间断裂,有什么想法吗?
我不确定您是否可以指定不绘制每个矩形的边缘之一。因此,一种想法是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] 删除。
我来说两句