question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unnormalized y-axis when using KDE

See original GitHub issue

When I do

sns.distplot(my_data, rug=True, norm_hist=False)

I get:

screen shot 2015-03-19 at 8 06 28 pm

and when I do:

sns.distplot(my_data, rug=True, norm_hist=False)

I get:

screen shot 2015-03-19 at 8 04 15 pm

Is there any way to have the Y-axis show raw counts (as in the 1st example above), when adding a kde plot? (2nd example above)?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:6
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

24reactions
mbernstecommented, Aug 6, 2017

It would be more informative than decorative. KDE and histogram summarize the data in slightly different ways. In general, when plotting a KDE, I don’t really care about what the actual values of the density function are at each point in the domain. Rather, I care about the shape of the curve. This contrasts with the histogram in which the values of each bar are something much more interpretable (number of samples in each bin).

Thus, it would be great to set the normalization of the KDE so that the density function integrates to a custom value thereby allowing the curve to be overlaid on the histogram.

11reactions
dmitriibeliakovcommented, Sep 30, 2017

Here’s my solution:

# Plotting hist without kde
ax = sns.distplot(filtered_bookings.booking_window, kde=False)

# Creating another Y axis
second_ax = ax.twinx()

#Plotting kde without hist on the second Y axis
sns.distplot(filtered_bookings.booking_window, ax=second_ax, kde=True, hist=False)

#Removing Y ticks from the second axis
second_ax.set_yticks([])

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is y axis in seaborn distplot figure? - Stack Overflow
When you are only showing the histogram ( kde=False ) and you don't normalize ( norm_hist=False ), then the y-axis represents the count...
Read more >
why does y axis sometimes change from normal histogram to ...
KDE is not the same as normalized histogram but for simplicity you can think like we normalize the curve with 1/AUC . If...
Read more >
Distributions — Elements of Data Science - GitHub Pages
A kernel density estimate (KDE), which is like a smooth, continuous version of a histogram. For examples, we'll use data from the General...
Read more >
Example of time KDE. The x-axis is unit fraction of one day ...
The x-axis is unit fraction of one day. Gaussian kernels for individual events are summed in order to compute the density of events...
Read more >
Home - KDE Community
KDE Applications. Powerful, multi-platform, and for everyone. Use KDE software to surf the web, keep in touch with colleagues, friends and family ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found