Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data points from Seaborn distplot

Tags:

I use

sns.distplot 

to plot a univariate distribution of observations. Still, I need not only the chart, but also the data points. How do I get the data points from matplotlib Axes (returned by distplot)?

like image 252
tesgoe Avatar asked May 22 '16 13:05

tesgoe


People also ask

How do you interpret seaborn Distplot?

Seaborn Distplot represents the overall distribution of continuous data variables. The Seaborn module along with the Matplotlib module is used to depict the distplot with different variations in it. The Distplot depicts the data by a histogram and a line in combination to it.

Is Distplot deprecated?

This function has been deprecated and will be removed in seaborn v0. 14.0. It has been replaced by histplot() and displot() , two functions with a modern API and many more capabilities.

Can seaborn generate graphic plots?

The main idea of Seaborn is that it provides high-level commands to create a variety of plot types useful for statistical data exploration, and even some statistical model fitting. Let's take a look at a few of the datasets and plot types available in Seaborn.

Does seaborn have interactive plots?

Behind the scenes, seaborn uses matplotlib to draw its plots. For interactive work, it's recommended to use a Jupyter/IPython interface in matplotlib mode, or else you'll have to call matplotlib. pyplot. show() when you want to see the plot.


1 Answers

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]
like image 174
Nils Gudat Avatar answered Sep 21 '22 07:09

Nils Gudat