Solution for Seaborn kdeplot cumulative not rising to 1 when split by hue
is Given Below:
Trying to use the sns.kdeplot() and keep running into an issue where the cumulative doesnt rise to one. This seems to predominantly occur when there is a large imbalance in the categories.
Any ideas what might be causing the normalization to not work as intended?
Create Sample Data
import pandas as pd # 1.1.0 import numpy as np # 1.18.1 import seaborn as sns # 0.11.1 np.random.seed(42) sim_data = [[x,np.random.random(),'A' if x < 250 else 'B'] for x in np.arange(0,1000000)] sim_data = pd.DataFrame(sim_data,columns=['Index','Value','Category'])
Plot Split by Hue (Left Hand Chart)
sns.kdeplot( data=sim_data, x='Value', hue="Category", common_norm=False, common_grid=True, cumulative=True )
Plot Split by Hue Single Category (Right Hand Chart)
sns.kdeplot( data=sim_data[sim_data['Category']=='A'], x='Value', hue="Category", common_norm=False, common_grid=True, cumulative=True )
Changing the common_grid = True to common_grid = False seems to resolve above.