# Ff.create\_distplot keeps giving non-normalized histograms/kde's

**URL:** <https://community.plotly.com/t/ff-create-distplot-keeps-giving-non-normalized-histograms-kdes/23410>\
**Category:** 📊 Plotly Python\
**Created:** [May 13, 2019, 11:35pm UTC](https://community.plotly.com/t/ff-create-distplot-keeps-giving-non-normalized-histograms-kdes/23410 "2019-05-13T23:35:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike3](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Mike3](https://community.plotly.com/u/Mike3)\
**Post date:** [May 13, 2019, 11:35pm UTC](https://community.plotly.com/t/ff-create-distplot-keeps-giving-non-normalized-histograms-kdes/23410/1 "2019-05-13T23:35:36Z")

</div>

This is a pretty simple bug, or some weird functionality that I do not understand, and would like help with.

I am using `ff.create_distplot()` in my Dash app, when I noticed _sometimes_ I don’t get all the y-values within the range `[0,1]`.

The following MWE demonstrates this. Run it once, then simply un-comment the second `x1` and `x2`, to see it happen on the second run. I believe this happens when the numbers are too bunched together, but that should not cause such a behavior either way.

```
import plotly.plotly as py
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.figure_factory as ff

import numpy as np

x1 = np.random.randn(10) - 2 
x2 = np.random.randn(10)

# x1 = [0.0, 0.0, 0.0, 0.0, 0.5, -0.12500000000000003, 0.0, -0.4, 0.0, 0.25]
# x2 = [-0.5, 0.0, 0.8375, 0.75, -0.8, 0.6, -1.0, -0.5999999999999999, 0.7, 0.85]

hist_data = [x1, x2]

group_labels = ['Group 1', 'Group 2']
colors = ['#A56CC1', '#A6ACEC']

# Create distplot with curve_type set to 'normal'
fig = ff.create_distplot(hist_data, group_labels, colors=colors,
                         bin_size=.2, show_rug=False)

# Add title
fig['layout'].update(title='Hist and Curve Plot')

# Plot!
iplot(fig, filename='Hist and Curve')
```

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [May 14, 2019, 1:13pm UTC](https://community.plotly.com/t/ff-create-distplot-keeps-giving-non-normalized-histograms-kdes/23410/2 "2019-05-14T13:13:17Z")

</div>

Best for #api:python forums

---

<div class="post-metadata">

**Author:** ![Mike3](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Mike3](https://community.plotly.com/u/Mike3)\
**Post date:** [May 14, 2019, 4:54pm UTC](https://community.plotly.com/t/ff-create-distplot-keeps-giving-non-normalized-histograms-kdes/23410/3 "2019-05-14T16:54:10Z")

</div>

Just updated tag now.

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [May 16, 2019, 11:33am UTC](https://community.plotly.com/t/ff-create-distplot-keeps-giving-non-normalized-histograms-kdes/23410/4 "2019-05-16T11:33:24Z")

</div>

Hi @Mike3,

The `histnorm` parameter to `create_distplot()` controls how the histograms are normalized. The default is `'probability density'`, which normalizes the bars so the the total _area_ of all of the bars is 1. If you switch this to `'probability'` then then sum of the heights of all of the bars will be 1.

Hope that helps,  
-Jon

---

<div class="post-metadata">

**Author:** ![Mike3](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Mike3](https://community.plotly.com/u/Mike3)\
**Post date:** [May 16, 2019, 6:27pm UTC](https://community.plotly.com/t/ff-create-distplot-keeps-giving-non-normalized-histograms-kdes/23410/5 "2019-05-16T18:27:46Z")

</div>

jmmease, I did the following, editing the `hisrnorm` parameter to `probability` for all the traces `create_distplot()` returns, and the bars are indeed fixed now, but what about the kde lines? ☹

This is what I get:

 ![23%20PM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/d/d9972c3b395ab06e1f2f8fb1d858ddea31d517b8.png)

Is there any way to also “normalize” the kde lines, so they lay below 1, matching the bars?

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [May 17, 2019, 10:29am UTC](https://community.plotly.com/t/ff-create-distplot-keeps-giving-non-normalized-histograms-kdes/23410/6 "2019-05-17T10:29:39Z")

</div>

Hi @Mike3,

> Is there any way to also “normalize” the kde lines, so they lay below 1, matching the bars?

No, the KDE is an estimate of the probability density function of the distribution. By definition, the integral (area under the curve) should be 1. Unlike a histogram, since a pdf is continuous it’s not really meaningful to talk about the sum of the heights of the distribution.

Hope that makes sense,  
-Jon
