python从低到高排序_使用python对matplotlib直方图中的xaxis值从最低值到最高值排序...
我認為既然您已經在使用matplotlib,那么在pandas中進行數據爭用也更有意義。在In [101]: JSON = '''[{"first":"A","second":"1","third":"2"},
.....: {"first":"B","second":"1","third":"2"},
.....: {"first":"C","second":"2","third":"2"},
.....: {"first":"D","second":"3","third":"2"},
.....: {"first":"E","second":"3","third":"2"},
.....: {"first":"F","second":"3","third":"2"},
.....: {"first":"G","second":"3","third":"2"},
.....: {"first":"H","second":"4","third":"2"},
.....: {"first":"I","second":"4","third":"2"},
.....: {"first":"J","second":"0","third":"2"},
.....: {"first":"K","second":"0","third":"2"},
.....: {"first":"L","second":"0","third":"2"},
.....: {"first":"M","second":"0","third":"2"},
.....: {"first":"N","second":"0","third":"2"}]
.....: '''
In [102]: df = pd.read_json(JSON)
In [103]: df
Out[103]:
first second third
0 A 1 2
1 B 1 2
2 C 2 2
3 D 3 2
4 E 3 2
5 F 3 2
6 G 3 2
7 H 4 2
8 I 4 2
9 J 0 2
10 K 0 2
11 L 0 2
12 M 0 2
13 N 0 2
In [104]: df.groupby('second').size().plot(kind='bar')
Out[104]:
條形圖將您的類別按正確的順序排列。在
但是,如果您只需要一個通用方法來排列條形圖,則可以構建一個臨時數據幀,對其進行排序,然后繪制:
^{pr2}$
總結
以上是生活随笔為你收集整理的python从低到高排序_使用python对matplotlib直方图中的xaxis值从最低值到最高值排序...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python3堆排序_python 堆排
- 下一篇: 能直接挂在iis的动静态网站_网站优化思