gada [dot] space

Kernel Density Estimate Plots

KDE plots are great for looking at distributions. These are my favorite settings with seaborn for making KDE plots. Substitute data with your own dataset. Adjust bins based on your data. I usually adjust bins to a tenth of the data volume, but make sure to make the bins even more detailed if you’d prefer.

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

points = 500
data = np.random.normal(0, 0.5, points)

sns.distplot(data,
             hist=True,
             kde=True,
             bins=int(points/10),
             color = 'darkblue',
             hist_kws = {'edgecolor':'black'},
             kde_kws = {'linewidth': 1.5})

plt.savefig('hist.png')
return('hist.png')
Menu