python - 如何在 Matplotlib 的水平条形图中将最大比例放在顶部?
问题描述
在下面,我创建了一个水平条形图。然而,最低的比例在顶部。我是 Pandas 和 Matplotlib 的新手,所以我希望你能向我展示一种将最大比例放在顶部的简单方法。
plt.style.use('fivethirtyeight')
total = 9674
langs = ['Computer science, computer engineering, or software engineering',
'Another engineering discipline (such as civil, electrical, mechanical, etc.)',
'Information systems, information technology, or system administration',
'A natural science (such as biology, chemistry, physics, etc.)',
'Mathematics or statistics',
'A humanities discipline (such as literature, history, philosophy, etc.)',
'A social science (such as anthropology, psychology, political science, etc.)',
'A business discipline (such as accounting, finance, marketing, etc.)',
'Fine arts or performing arts (such as graphic design, music, studio art, etc.)',
'Web development or web design',
'I never declared a major',
'A health science (such as nursing, pharmacy, radiology, etc.)']
fig, ax = plt.subplots()
langs_users_num = np.array([5387, 764, 687, 528, 420, 407, 392, 385, 327, 212, 128, 37])
percent = langs_users_num/total*100
new_labels = [i+' {:.2f}%'.format(j) for i, j in zip(langs, percent)]
plt.barh(langs, langs_users_num, color='lightskyblue', edgecolor='blue')
plt.yticks(range(len(langs)), new_labels)
plt.tight_layout()
for spine in ax.spines.values():
spine.set_visible(False)
figure(num=None, figsize=(20, 20), dpi=100, facecolor='w', edgecolor='k')
ax.axes.get_xaxis().set_visible(False)
ax.tick_params(axis="y", left=False)
plt.show()
#plt.tight_layout()
解决方案
推荐阅读
- git - 为什么 IntelliJ 会自动将我的“开发”分支中的更改加载到“主”分支中?
- html - 创建具有非滚动列标题的 CSS 网格
- c++ - Qt5 - C++ - QImage - 不正确缩放
- vsto - 如何在 C# 中将“公共部分类 ThisWorkbook”添加到 VSTO 应用程序?
- javascript - 将 prop 值传递给 svg Vue.js 组件中动态构建的点击事件
- android - 如何在本机反应中将事件添加到谷歌日历
- excel - Excel VBA代码用于从选择行中自动填充序列号
- python - 为什么增加Epoch后损失函数输出NaN?
- sql - SqlCmd 命令执行停止
- android - 如何始终在 exoplayer 中显示进度条和时间