python 3.x - Getting a single merged histogram for two different variable but want two different plot -
python code plotting histogram
seaborn.distplot(sub2["s2aq16a"].dropna(), kde=false); plt.xlabel('age') plt.title('age when started drinking') seaborn.distplot(sub2["sibno"].dropna(), kde=false); plt.xlabel('no. of siblings') plt.title('no. of siblings alcoholic')
i expected output 2 histogram individual variables.but got histogram both variable merged in one. here screenshot of output.
if run code 1 one plotting histogram single variable while leaving code plotting histogram of other variable comment, correct output.
you plotting both histograms on same axes. if want them separate, plot them on different axes. here's 1 way of doing it.
fig, axes = plt.subplots(2, 1) seaborn.distplot(sub2["s2aq16a"].dropna(), kde=false, ax=axes[0]); axes[0].set_xlabel('age') axes[0].set_title('age when started drinking') seaborn.distplot(sub2["sibno"].dropna(), kde=false, ax=axes[1]); axes[1].set_xlabel('no. of siblings') axes[1].set_title('no. of siblings alcoholic') plt.tight_layout()
Comments
Post a Comment