Using distplot in Python

What is the y-axis unit when using distplot to plot a histogram? I built various histograms along with a normal fit, and I see that in one case it has a range from 0 to 0.9, and in the other from 0 to 4.5.

Thanks.

+6
source share
1 answer

From help(sns.distplot) :

norm_hist: bool, otional If True, the height of the histogram indicates density, not count. This is implied in building a KDE density or density.

The density is scaled so that the area under the curve is 1, so no single box will ever be higher than 1 (the entire data set) [2]. But kde is enabled by default and overrides norm_hist, so norm_hist changes y-units only if you explicitly disable kde:

 import matplotlib.pyplot as plt import numpy as np import seaborn as sns fig, axs = plt.subplots(figsize=(6,6), ncols=2, nrows=2) data = np.random.randint(0,20,40) for row in (0,1): for col in (0,1): sns.distplot(data, kde=row, norm_hist=col, ax=axs[row, col]) axs[0,0].set_ylabel('NO kernel density') axs[1,0].set_ylabel('KDE on') axs[1,0].set_xlabel('norm_hist=False') axs[1,1].set_xlabel('norm_hist=True') 

enter image description here

[2] clarification from mwaskom, thanks!

+6
source

Source: https://habr.com/ru/post/985646/


All Articles