Home > Visualization > Main text

Distribution/hist plot


Tag: plot, visualization

Call hist function from plt stackoverflow

fig,ax = plt.subplots()

bins = np.linspace(0.3, 0.8, 70)

ax.hist(d_g['col1'], bins=bins)
mean1 = np.mean(d_g['col1'])
ax.hist(d_g['col2'], bins=bins)
mean2 = np.mean(d_g['col2'])

plt.axvline(x=mean1, ymin=0, ymax=1, ls='--')
plt.axvline(x=mean2, ymin=0, ymax=1, ls='--')

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

Call from sns.dist function

fig,ax = plt.subplots()

sns.distplot(d_g['col1'].dropna(), bins=100,kde=False, norm_hist=0, color='#d02e30',ax=ax, label='col1')
sns.distplot(d_g['col2'].dropna(), bins=100,kde=False, norm_hist=0, color='#447dab',ax=ax, label='col2')

mean1 = np.mean(d_g['col1'])
mean2 = np.mean(d_g['col2'])

ax.axvline(x=mean1, ymin=0, ymax=1, ls='--', color='#d02e30', )
ax.axvline(x=mean2, ymin=0, ymax=1, ls='--', color='#447dab', )

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

If you link this blog, please refer to this page, thanks!
Post link:https://tsinghua-gongjing.github.io/posts/distplot.html

Previous: Box plot