Get data points from Seaborn distplot

You can use the matplotlib.patches API. For instance, to get the first line:

sns.distplot(x).get_lines()[0].get_data()

This returns two numpy arrays containing the x and y values for the line.

For the bars, information is stored in:

sns.distplot(x).patches

You can access the bar’s height via the function patches.get_height():

[h.get_height() for h in sns.distplot(x).patches]

Leave a Comment