2017-06-21 6 views
1

ヒストグラムを生成するコードは次のとおりです。完全なコードのために、あなたは、私が強調表示/日陰曲線下面積で滑らかな曲線に、このヒストグラムを変換するにはどうすればよいこのiPython Notebook2つの変数をプロットしたヒストグラムを滑らかな曲線に変換します

# Splitting the dataset into malignant and benign. 
dataMalignant=datas[datas['diagnosis'] ==1] 
dataBenign=datas[datas['diagnosis'] ==0] 

#Plotting these features as a histogram 
fig, axes = plt.subplots(nrows=10, ncols=1, figsize=(15,60)) 
for idx,ax in enumerate(axes): 
    ax.figure 
    binwidth= (max(datas[features_mean[idx]]) - min(datas[features_mean[idx]]))/250 
    ax.hist([dataMalignant[features_mean[idx]],dataBenign[features_mean[idx]]], bins=np.arange(min(datas[features_mean[idx]]), max(datas[features_mean[idx]]) + binwidth, binwidth) , alpha=0.5,stacked=True, normed = True, label=['M','B'],color=['r','g']) 
    ax.legend(loc='upper right') 
    ax.set_title(features_mean[idx]) 
plt.show() 

Histogram

を参照することができます。ここ

+0

のようなものを使用しますが、ヒストグラムデータを取得できません配列とプロットの配列として? – Mochan

+0

私はおそらく一種の散布図を作成すると思います。私はたくさんの方法を試しましたが、私が探していたものはどれもありませんでした。 – Djokester

+0

https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/scipy.optimize.curve_fit.htmlとhttps://docs.scipy.org/doc/scipy/reference/statsを使用してください。 html、適切な分布候補のためのあなたの好みの確率密度関数の写真のためのGoogleイメージを見てきました。 –

答えて

0

はあなた

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt 
np.random.seed(123) 
datas = pd.DataFrame(np.random.randint(0, 2, size=(100, 1)), columns=['diagnosis']) 
datas['data'] = np.random.randint(0, 100,size=(100, 1)) 

に役立つかもしれない簡単な例である私は、numpyののhistogram機能を使用していますが、代わりに同じ引数でax.histを使用することができます。

benign_hist=np.histogram(datas[datas['diagnosis']==0]['data'],bins=np.arange(0, 100, 10)) 
malignant_hist=np.histogram(datas[datas['diagnosis']==1]['data'],bins=np.arange(0, 100, 10)) 

fig,ax=plt.subplots(1,1) 
ax.fill_between(malignant_hist[1][1:], malignant_hist[0], color='r', alpha=0.5) 
ax.fill_between(benign_hist[1][1:], benign_hist[0], color='b', alpha=0.5) 

上記の例では、bin midpointsではなくプロンプトの便宜のためにデモ用に9個のbin edgeを使用しました。 1はhist_data = ax.hist(...) HIST_DATAを割り当てることができOPのコードで

[0]ヒストグラム値とHIST_DATA 1が含まれていることは地域で埋めるためにビンを含んで

fig, ax=plt.subplots(1,1) 
ax.fill_between(hist_data[1][1:],hist_data[0][0],color='g',alpha=0.5) 
ax.fill_between(hist_data[1][1:],hist_data[0][1],color='r',alpha=0.5) 

filled histogram

関連する問題