SEABORN HISTOGRAM
Padhai - Classwork
padhai_histplot

Distribution of Data - Seaborn Package

In [15]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes = True)
In [8]:
x = np.random.normal(size=1000)
In [16]:
sns.distplot(x)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd182b36ed0>
In [17]:
sns.distplot(x, kde = False)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd182a61890>
In [13]:
sns.set(color_codes = True)
In [18]:
sns.distplot(x, kde = False, rug = True)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2103: FutureWarning: The `axis` variable is no longer used and will be removed. Instead, assign variables directly to `x` or `y`.
  warnings.warn(msg, FutureWarning)
Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd1829e8d50>
In [19]:
sns.distplot(x, bins=50, kde=False, rug=True)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2103: FutureWarning: The `axis` variable is no longer used and will be removed. Instead, assign variables directly to `x` or `y`.
  warnings.warn(msg, FutureWarning)
Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd18112fc50>
In [20]:
sns.kdeplot(x)
Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd1888897d0>
In [21]:
sns.kdeplot(x, shade=True)
Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd180966210>
In [22]:
y = np.random.uniform(size=1000)
In [25]:
sns.kdeplot(y, shade=True)
sns.kdeplot(x, shade=True);

with real datasets from seaborn package

In [26]:
d = sns.load_dataset('diamonds')
In [27]:
d
Out[27]:
carat cut color clarity depth table price x y z
0 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
2 0.23 Good E VS1 56.9 65.0 327 4.05 4.07 2.31
3 0.29 Premium I VS2 62.4 58.0 334 4.20 4.23 2.63
4 0.31 Good J SI2 63.3 58.0 335 4.34 4.35 2.75
... ... ... ... ... ... ... ... ... ... ...
53935 0.72 Ideal D SI1 60.8 57.0 2757 5.75 5.76 3.50
53936 0.72 Good D SI1 63.1 55.0 2757 5.69 5.75 3.61
53937 0.70 Very Good D SI1 62.8 60.0 2757 5.66 5.68 3.56
53938 0.86 Premium H SI2 61.0 58.0 2757 6.15 6.12 3.74
53939 0.75 Ideal D SI2 62.2 55.0 2757 5.83 5.87 3.64

53940 rows × 10 columns

In [28]:
d.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 53940 entries, 0 to 53939
Data columns (total 10 columns):
 #   Column   Non-Null Count  Dtype   
---  ------   --------------  -----   
 0   carat    53940 non-null  float64 
 1   cut      53940 non-null  category
 2   color    53940 non-null  category
 3   clarity  53940 non-null  category
 4   depth    53940 non-null  float64 
 5   table    53940 non-null  float64 
 6   price    53940 non-null  int64   
 7   x        53940 non-null  float64 
 8   y        53940 non-null  float64 
 9   z        53940 non-null  float64 
dtypes: category(3), float64(6), int64(1)
memory usage: 3.0 MB
In [30]:
sns.distplot(d.carat)
# the outcome is not uni-modal distribution
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
Out[30]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd17ff84290>
In [32]:
sns.distplot(d.price)
# the outcome is a long tailed distribution - right skewed distribution
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
Out[32]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd17ff98b90>
In [33]:
sns.distplot(d.x)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
Out[33]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd17fb9d510>
In [34]:
sns.distplot(d.x, rug=True)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2103: FutureWarning: The `axis` variable is no longer used and will be removed. Instead, assign variables directly to `x` or `y`.
  warnings.warn(msg, FutureWarning)
Out[34]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd180619450>
In [35]:
sns.distplot(d.sample(1000).x, rug = True)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2103: FutureWarning: The `axis` variable is no longer used and will be removed. Instead, assign variables directly to `x` or `y`.
  warnings.warn(msg, FutureWarning)
Out[35]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd17fca8350>
In [36]:
sns.kdeplot(d.x)
sns.kdeplot(d.y)
sns.kdeplot(d.z)
Out[36]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd17fca8510>
In [37]:
sns.kdeplot(d.x, shade=True)
sns.kdeplot(d.y, shade=True)
sns.kdeplot(d.z, shade=True)
Out[37]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd17dcdcbd0>
In [39]:
sns.kdeplot(d.x, shade=True)
sns.kdeplot(d.y, shade=True)
# x and y dataset is almost similar in nature
Out[39]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd17db4e610>
In [ ]: