2016-11-17 11 views
0

2つのデータリストデータ値(それぞれ100個の数値)がありますd1 = [0.5,0.6,0.45、.......]、d2 = 0.45,0.65、........]。次の図のように2つのリストデータを使って2つのhistをプロットしたい! matplotlibでプロットする方法、ありがとう!python3:matplotlibで2つのリストデータでヒストグラムをプロットする方法

def plot_data(d1, d2): 
    fig, ax = plt.subplots() 
    ax.hist(d1, 100, 50, ec='red', fc='none', lw=1.5, histtype='step', label='n-gram') 
    ax.hist(d2, 100, 50, ec='green', fc='none', lw=1.5, histtype='step', label='ensemble') 
    ax.legend(loc='upper left') 
    plt.show() 

をが、エラーがあります: 私のコードは次のとおりです

mn, mx = [mi + 0.0 for mi in range] 
TypeError: 'int' object is not utterable 

two hist with two data lists

+1

参照してください。 – harshil9968

+1

@ harshil9968が言っていることは、エラーがそのようなデータをプロットすることと何らかの関係があることを示しているという証拠はないということです。 – Gormador

答えて

2

あなたのエラーがhist()関数の3番目の引数から来ています。 hist()ためRead the documentation

Parameters: x : (n,) array or sequence of (n,) array (...)

bins : integer or array_like, optional (...)

range : tuple or None, optional

The lower and upper range of the bins. Lower and upper outliers are ignored. If not provided, range is (x.min(), x.max()). Range has no effect if bins is a sequence.**

If bins is a sequence or range is specified, autoscaling is based on the specified bin range instead of the range of x.

Default is None

3番目のパラメータはtupleまたはNoneのいずれかである必要があり、50(int)を提供してきました。

はあなたにエラーを与えているこのコードで私は単に Noneで第3引数を置き換え(およびビンの数を削減)以下のコードを、

d1 = np.random.normal(size=(100,)) 
d2 = 1+np.random.normal(size=(100,)) 

fig, ax = plt.subplots() 
ax.hist(d1, 10, None, ec='red', fc='none', lw=1.5, histtype='step', label='n-gram') 
ax.hist(d2, 10, None, ec='green', fc='none', lw=1.5, histtype='step', label='ensemble') 
ax.legend(loc='upper left') 
plt.show() 

enter image description here

+0

@Diziet Asahiのお返事ありがとうございました – tktktk0711

+0

私の回答が役に立った場合は、左側のチェックマークをクリックして受け付けてください –

関連する問題