python - 按总值对堆积柱形图进行排序 - Python
问题描述
这是我绘制的数据框:
JP_Sales NA_Sales EU_Sales
Genre
Action 158.66 861.80 516.48
Adventure 52.01 102.06 63.79
Fighting 87.15 220.74 100.00
Misc 106.67 402.48 213.82
Platform 130.65 445.99 200.67
Puzzle 56.68 122.01 50.53
Racing 56.61 356.93 236.32
Role-Playing 350.29 326.50 187.58
Shooter 38.18 575.16 310.45
Simulation 63.54 181.78 113.20
Sports 134.76 670.09 371.34
Strategy 49.10 67.89 44.94
使用此代码:
Genre_sales.plot.bar(stacked=True, figsize = (10,10))
plt.suptitle('Total Sales by Genre, separated by Region')
plt.xlabel('Genre')
plt.ylabel('Total Units Sold (Millions)')
解决方案
如果您使用排序顺序索引到数据框,那么应该这样做:
Genre_sales.loc[df.sum(axis=1).sort_values().index].plot.bar(stacked=True, figsize=(10,10))
推荐阅读
- scala - 通用高级类型
- javascript - AngularJS Ng-Repeat 仅在子子行上
- python - Django 请求会话无法读取 django-session 表
- c# - 运行 Ranorex/Neoload 测试时未找到 [ProtocolSAPGUI] 的属性或关联
- javascript - 单击选项时如何关闭菜单?简单的 JS,但我不能这样做:/
- python - 无列表逐行比较 2 个文件
- java - 从Java中的字符串中删除不可打印的字符
- frama-c - Frama-C:在命令行输出中显示调用堆栈
- c# - 以编程方式完成条件业务流程时抛出异常
- visual-studio-code - VS Code 触摸板滚动移动光标而不是页面