Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Seaborn distplot not support a range?

I have an array of data, called data1, that contains values from 0 to more than a thousand. I only want to have a histogram and a KDE of those values from 0 to 10. Hence I wrote:

sns.distplot(data1, kde=True, hist=True, hist_kws={"range": [0,10]})
plt.show()

What I get however is a histogram of all values (well into 2000s).

like image 636
sbm Avatar asked May 06 '16 18:05

sbm


People also ask

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.

What does Distplot () mean in SNS Distplot ()?

distplot() The seaborn. distplot() function accepts the data variable as an argument and returns the plot with the density distribution. Example 1: import numpy as np import seaborn as sn import matplotlib.

What can I use instead of a Distplot?

For simple plots where x is a vector of data, displot(x) and histplot(x) are drop-in replacements for distplot(x) .


1 Answers

You could just filter your data and call displot over the filtered data:

filtered = data1[(data1 >= 0) & (data1 < 10)]
sns.distplot(filtered, kde=True, hist=True, hist_kws={"range": [0,10]})
plt.show()

Assuming data1 is a numpy array.

like image 81
Imanol Luengo Avatar answered Sep 27 '22 22:09

Imanol Luengo