def stackhist(x, y, **kws):
grouped = pd.groupby(x, y)
data = [d for _, d in grouped]
labels = [l for l, _ in grouped]
plt.hist(data, histtype="barstacked",
label=labels, alpha=0.8, normed=True,
bins=np.arange(4.0, 8.1, 0.25))
plt.ylim([0, 0.6])
plt.xlim([4, 8])
plt.xlabel('Sepal Width [cm]')
plt.ylabel('Frequency')
with plt.style.context('fivethirtyeight'):
stackhist(df[0], df['class'])
#plt.legend(['Setosa', 'Virginica', 'Versicolor'], fontsize=12)
plt.title('All')
plt.tight_layout()
plt.savefig('./all.svg')
plt.show()
stackhist(df_train[0], df_train['class'])
plt.title('Train')
plt.tight_layout()
#plt.savefig('./train.svg')
plt.show()
stackhist(df_test[0], df_test['class'])
plt.title('Test')
plt.tight_layout()
#plt.savefig('./test.svg')
plt.show()
"""
fig = plt.figure()
figlegend = plt.figure(figsize=(3,4))
ax = fig.add_subplot(111)
lines = ax.plot(range(10), np.random.randn(10), range(10), np.random.randn(10), np.random.randn(10), range(10),)
figlegend.legend(lines, ['Setosa', 'Virginica', 'Versicolor'], 'center')
fig.show()
figlegend.show()
figlegend.savefig('legend.svg')
"""