2017-06-22 10 views
0

簡単な例:Python - Rのようにヒストグラムプロットを取得するには?

> v <- c(0.1,0.2,0.3,0.4,0.5) 
> names(v) <- c(1,2,3,4,5) 
> v 
    1 2 3 4 5 
0.1 0.2 0.3 0.4 0.5 
> plot(v,type='h') 

私のpythonとまったく同じプロットを得るのに苦労しています

enter image description here

が得られます。 matplotlibヒストグラムを使用すると、インデックスをプロットしません。 (Rはそうだと思われますが)

これに関する提案はありますか?

答えて

1

値が既にヒストグラムデータであるため、実際にはヒストグラムは必要ありません。

は、代わりにあなたは0

import matplotlib.pyplot as plt 

v = [0.1,0.2,0.3,0.4,0.5] 

plt.bar(range(len(v)), v, width=0, ec="k") 

plt.show() 

enter image description here

にバーの幅を設定することができ、代わりにバーの行を取得するためにbarplot

import matplotlib.pyplot as plt 

v = [0.1,0.2,0.3,0.4,0.5] 

plt.bar(range(len(v)), v) 

plt.show() 

enter image description here

を使用することができます

関連する問題