首页 > 解决方案 > Matplotlib 图形图例文本添加或修改

问题描述

我得到了熊猫数据框 matplotlib 的图表。图例顶部没有,只有情节文本在那里。如何在那里添加文本而不是没有,没有?

在此处输入图像描述

df[df.Dst_Port.eq(5353)].groupby('Dst_Port'['Packet_length'].agg({'Packet':['sum','min','max','mean', 'median','std']}).plot(kind='bar',title='Destination Portwise Packets', legend=True, ax=ax)

标签: pythonpandasmatplotlib

解决方案


如果您还没有这样做,请添加这些代码行以显示图例和标签。

plt.xlabel('X')
plt.ylabel('Y')
plt.title('Histogram')
plt.legend()

推荐阅读