Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas histogram in python. possible to make probability/density instead of count?

Histogram in pandas plots the count of each bin, rather than the normalized fraction. In R, this is an option in the histogram. Is it possible in Pandas? If not, any recommendations for an easy workaround?

like image 587
wolfsatthedoor Avatar asked Aug 29 '14 23:08

wolfsatthedoor


People also ask

How do you plot probability density function in Python?

You first create a plot object ax . Here, you can specify the number of bins in the histogram, specify the color of the histogram and specify density plot option with kde and linewidth option with hist_kws . You can also set labels for x and y axis using the xlabel and ylabel arguments.

Is a histogram a density plot?

Density Plot is the continuous and smoothed version of the Histogram estimated from the data. It is estimated through Kernel Density Estimation. In this method Kernel (continuous curve) is drawn at every individual data point and then all these curves are added together to make a single smoothened density estimation.

What is density plot in pandas?

Density Plot is a type of data visualization tool. It is a variation of the histogram that uses 'kernel smoothing' while plotting the values. It is a continuous and smooth version of a histogram inferred from a data.


1 Answers

For me this gives the desired results.

df = pd.DataFrame(np.random.randn(5000))
df.hist(normed = True)

The 'density' option works in numpy's histogram function but not on pandas's hist function.

like image 58
BKay Avatar answered Nov 13 '22 05:11

BKay