python - 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)
解决方案
如果您还没有这样做,请添加这些代码行以显示图例和标签。
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Histogram')
plt.legend()
推荐阅读
- c++ - 如何将 shared_ptr 提供给应将各种数据类型添加到向量的模板函数?
- mysql - 如何检查字符串列表中的至少一个字符串是否包含在另一个字符串中?
- java - 我的@DataMongoTest 有问题 - 抛出 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
- vue.js - 如何在“构建”之后设置 Vue 环境变量而不将它们包含在 JS 文件中?
- javascript - 增加/减少 DIV 和 PROGRESSBAR 值 CSS/JS - 定位元素
- jsp - ADF - selectOneChoice - 如果 valueChangeListener 没有更改,则始终触发它
- laravel - 模型事件未在播种机中触发
- azure-devops - 如何在 Azure DevOps Pipelines 中安排阶段部署?
- android - 如何用新文本替换软键盘输入连接文本
- sql - <<>> 运算符在 Athena SQL 中的含义