2016-12-24 10 views
0

pandas df.plotがy軸を降順で自動的にソートすることは非常に面倒です。pandas df.plot()がy軸をソートしないようにします

df1[:10].plot(x="Term",y="P-value",kind='barh') 

データフレーム内で何かを並べ替えてそのままプロットしたくないです。自動ソートを防ぐ方法はありますか?

私はドキュメントを見ようとしましたが、plot()には並べ替えを防ぐオプションがありませんでした。私はGoogleで試したが、私は解決策を見つけることができませんでした。

例ファイル(タブ区切り):

Term p-value 
De novo pyrimidine deoxyribonu 0.043726 
Interleukin signaling pathway_ 0.075241 
Plasminogen activating cascade 0.099365 
De novo purine biosynthesis_Ho 0.115435 
Alzheimer disease-presenilin p 0.142836 
Salvage pyrimidine ribonucleot 0.171718 
Pyrimidine Metabolism_Homo sap 0.171718 
Heterotrimeric G-protein signa 0.189208 
p53 pathway_Homo sapiens_P0005 0.215917 
Heterotrimeric G-protein signa 0.246512 

コードスニペット:

import matplotlib.pyplot as plt 
import pandas as pd 
df = pd.read_csv("test.txt",sep='\t') 
df.plot(x="Term",y="p-value",kind='barh') 
plt.show() 

enter image description here

答えて

0
In [33]: df.plot.barh(x='Term',y="p-value") 
Out[33]: <matplotlib.axes._subplots.AxesSubplot at 0xba4fb00> 

In [34]: plt.gca().invert_yaxis() # <--- this is the trick 

In [35]: plt.tight_layout() 

enter image description here

または手動

df.plot.barh(x=df.Term[::-1],y="p-value") 
plt.tight_layout() 

結果:トリックのための

enter image description here

+0

おかげで 'Y軸のデータを元に戻します – gthm

関連する問題