python - 使用 matplotlib 在条形顶部添加文本标签
问题描述
我有下面的python代码来使用matplotlib进行绘图。
我需要在每个数据栏顶部添加标签的帮助。
import numpy as np
import matplotlib.pyplot as plt
N = 4
ind = np.arange(N)
width = 0.25
xvals = [95.73,94.70,92.29,76.48]
bar1 = plt.bar(ind, xvals, width, color = 'r')
yvals = [78.47,76.65,63.61,41.58]
bar2 = plt.bar(ind+width, yvals, width, color='g')
zvals = [69.30,54.46,50.92,39.21]
bar3 = plt.bar(ind+width*2, zvals, width, color = 'b')
plt.xlabel("Teams")
plt.ylabel('Data (%)')
plt.title("Overall data")
plt.xticks(ind+width,['Team 1', 'Team 2', 'Team 3', 'Team 4'])
plt.legend( (bar1, bar2, bar3), ('Data 1', 'Data 2', 'Data 3') )
plt.show()
解决方案
推荐阅读
- reactjs - React TypeScript 接受 ComponentType 道具上缺少的道具
- flutter - 某些表情符号无法正确呈现颤动的文本字段
- docker - Docker-in-Docker 客户端 - 信任附加根证书
- python - Django 管理面板搜索栏不起作用(相关字段查找无效:icontains)
- python - 在 Pydantic 中定义递归模型?
- blazor - 是否可以为 Blazor 页面添加书签?
- c# - Tcp Listener 如何使用 ListViewItems 和 ContextMenuStrip 访问特定的 Tcp 客户端
- curl - 在 JIRA xray 中映射多个 Robot Framework 测试用例
- material-ui - 配置 eslint 使用默认导入
- arrays - 给定一个数 N 和一个排序数组 A,检查 A 中是否有两个数的乘积为 N