0

When I am using seaborn's kdeplot function I am getting a plot where the y-axis is in its actual count. I want it to show a value between 0 to 1. The kernel density normally should be between 0 and 1. But why it is still giving its actual value, what is wrong with it? I am using the following code:

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
inp1 = open('1BVN_g.txt', 'r')
val = []
for line in inp1:
    #print(line)
    a = line.rstrip()
    val.append(float(a))
    
val2 = np.array(val)
sns.kdeplot(val2, shade=True)
Ashyam
  • 666
  • 6
  • 13
  • I took a quick glance at the docs (<10 seconds) and think that the `hue_norm` parameter is something you should experiment with – Paul H Feb 16 '23 at 06:05
  • I tried with hue_norm=True and False both. But getting the same graph. But that is again showing the same curve. – Gargi Biswas Feb 16 '23 at 06:18
  • Did you read the docs? `hue_norm` doesn't accept bools as valid input – Paul H Feb 16 '23 at 06:34
  • 1
    You are misinterpreting what "normalized" means. It makes the total **area** below the curve equal to 1. The y-value can be quite high if the x-values are in a reduced range. Note that `hue_norm` is ignored here, as no `hue` is used. See [KDE on wikipedia](https://en.wikipedia.org/wiki/Kernel_density_estimation) to get more information about a kernel density estimation. Note that without reproducible test data and without seeing the plot you got, it is hard to know what you are doing exactly. – JohanC Feb 16 '23 at 08:04
  • @PaulH You made me wondering what this parameter is really about. It seems `hue_norm` only applies to the way lines are colored when working with a numeric hue. It has quite limited use here, as for a kdeplot needs hue needs to be restricted to a few discrete values. An example would be `sns.kdeplot(data=tips, x='total_bill', hue='size', hue_norm=plt.Normalize(1,3))` would use the same color for table sizes 3,4,5 and 6. But it still uses different curves for each individual table size. (This reasoning is also very similar for a 2D kdeplot). – JohanC Feb 16 '23 at 09:17

0 Answers0