python - 用百分比绘制条形图
问题描述
我需要一些帮助来绘制带有百分比的条形图。我需要这样的情节:
bar of overall males bar of overall females
bar of hired males bar of hired females
x axis: Males, Females
我正在尝试这样的事情:
y = [139437,689] # [Overall Males, Hired Males]
z = [82693,545] # [Overall Females, Hired Females]
x = [Males, Females] # on x-axis
ax = plt.subplot()
ax.bar(x-0.1, y, width=0.1, color='b')
ax.bar(x, z, width=0.1, color='g')
plt.show()
请帮我解决这里的代码。
解决方案
您想要实现的目标可能是
import matplotlib.pyplot as plt
y = [139437, 82639] # [Overall Males/Females]
z = [689, 545] # [Hired Males/Females]
x = ['Males', 'Females'] # on x-axis
ax = plt.subplot()
ax.bar(x, y, width=0.5, color='b', label='all')
ax.bar(x, z, width=0.5, color='g', label='hired')
plt.legend()
plt.show()
但请注意,总体值和雇用值之间的差异如此之大,根据您的目的,这种可视化可能不是最好的。
推荐阅读
- r - 如何使用多张工作表导入多个 excel 文件?
- java - Instagram 分享验证
- javascript - 更改 Node.js 中动态加载模块的全局范围
- android - 离子角http帖子在设备上不起作用,但在浏览器上工作正常
- java - 将 sourceCompatility 设置为 1.6 后出现错误 - 不支持的 major.minor 版本 52.0
- android - 网站上传 Android 应用程序供其他人查看
- powerquery - Power Query - 填写特殊文本条件
- javascript - 如何将 HTML 元素(例如 Canvas)塑造为多边形?
- python-3.x - Python 3,ODM(umongo),关系字段的困难
- mongodb - mongodb用户无需任何身份验证即可登录