[英]How can I automate the ordering of a Stacked Bar plot in Python using Matplotlib?
I am currently creating a stacked bar plot using a dataframe and I'd like to change the ordering of the bars in order of magnitude.我目前正在使用 dataframe 创建一个堆叠条 plot ,我想按数量级更改条的顺序。 I have a dataframe as following:我有一个 dataframe 如下:
df = (
H C O
A 2 1 3
B 1 2 1
C 3 1 1
D 1 2 3
E 1 3 1)
df.plot.bar(stacked = True).legend(loc='upper center', ncol=3)
The problem I am coming into is that the first column has priority in ordering.我遇到的问题是第一列优先排序。 I would like an output that stacks bars in increasing value found in each column.我想要一个 output 以在每列中发现的递增值堆叠条形。
I am not opposed to sending each row into a new list, or dataframe, or indices and plotting them separately and then concatanting, but I am very new to Python.我不反对将每一行发送到一个新列表或 dataframe 或索引并分别绘制它们然后连接,但我对 Python 非常陌生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.