0% found this document useful (0 votes)
49 views1 page

seaborn

The document contains a series of Python code snippets demonstrating the use of the Seaborn library for data visualization, including plotting distributions, count plots, and box plots using datasets such as Titanic and Iris. It also includes warnings about deprecated functions and future changes in the libraries used. The code illustrates various visualizations such as histograms, scatter plots, and line plots, along with user warnings regarding library versions and deprecated features.

Uploaded by

Satya Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views1 page

seaborn

The document contains a series of Python code snippets demonstrating the use of the Seaborn library for data visualization, including plotting distributions, count plots, and box plots using datasets such as Titanic and Iris. It also includes warnings about deprecated functions and future changes in the libraries used. The code illustrates various visualizations such as histograms, scatter plots, and line plots, along with user warnings regarding library versions and deprecated features.

Uploaded by

Satya Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

In [1]: import seaborn as sns

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt

/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/pandas/core/arrays/masked.py:60: UserWarning: Pandas requires version '1.3.6' or newer of 'bottleneck' (version '1.3.5' currently installed).
from pandas.core import (

In [2]: x = np.array([0,1,2,3,4,5,6,7,8,9])

In [9]: sns.distplot(x,hist=False)
plt.show()

/var/folders/nn/9bkkh7612wg2c3gglt0zd9h40000gn/T/ipykernel_19528/2451510118.py:1: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

Please adapt your code to use either `displot` (a figure-level function with
similar flexibility) or `kdeplot` (an axes-level function for kernel density plots).

For a guide to updating your code to use the new functions, please see
https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751

sns.distplot(x,hist=False)
/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):

In [10]: sns.distplot(np.random.normal(size=1000),hist=False)
plt.show()

/var/folders/nn/9bkkh7612wg2c3gglt0zd9h40000gn/T/ipykernel_19528/4257869092.py:1: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

Please adapt your code to use either `displot` (a figure-level function with
similar flexibility) or `kdeplot` (an axes-level function for kernel density plots).

For a guide to updating your code to use the new functions, please see
https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751

sns.distplot(np.random.normal(size=1000),hist=False)
/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):

In [12]: sns.distplot(np.random.random(1000),hist=False)
plt.show()

/var/folders/nn/9bkkh7612wg2c3gglt0zd9h40000gn/T/ipykernel_19528/2758520570.py:1: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

Please adapt your code to use either `displot` (a figure-level function with
similar flexibility) or `kdeplot` (an axes-level function for kernel density plots).

For a guide to updating your code to use the new functions, please see
https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751

sns.distplot(np.random.random(1000),hist=False)
/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):

In [13]: #load dataset - cleaned titanic

In [14]: df = pd.read_csv('cleaned_titanic.csv')

In [15]: df

Out[15]: Unnamed: 0 survived pclass sex age sibsp parch fare embarked class who adult_male embark_town alive alone

0 0 0 3 male 22.000000 1 0 7.2500 S Third man True Southampton no False

1 1 1 1 female 38.000000 1 0 71.2833 C First woman False Cherbourg yes False

2 2 1 3 female 26.000000 0 0 7.9250 S Third woman False Southampton yes True

3 3 1 1 female 35.000000 1 0 53.1000 S First woman False Southampton yes False

4 4 0 3 male 35.000000 0 0 8.0500 S Third man True Southampton no True

... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

886 886 0 2 male 27.000000 0 0 13.0000 S Second man True Southampton no True

887 887 1 1 female 19.000000 0 0 30.0000 S First woman False Southampton yes True

888 888 0 3 female 29.699118 1 2 23.4500 S Third woman False Southampton no False

889 889 1 1 male 26.000000 0 0 30.0000 C First man True Cherbourg yes True

890 890 0 3 male 32.000000 0 0 7.7500 Q Third man True Queenstown no True

891 rows × 15 columns

In [16]: sns.countplot(x = 'sex',data=df)


plt.show()

In [17]: sns.countplot(x = 'sex',hue='pclass',data=df)


plt.show()

In [18]: #plot the distribution of age column

In [20]: sns.distplot(df['age'],hist=False)
plt.show()

/var/folders/nn/9bkkh7612wg2c3gglt0zd9h40000gn/T/ipykernel_19528/2719210385.py:1: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

Please adapt your code to use either `displot` (a figure-level function with
similar flexibility) or `kdeplot` (an axes-level function for kernel density plots).

For a guide to updating your code to use the new functions, please see
https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751

sns.distplot(df['age'],hist=False)
/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):

In [21]: sns.countplot(y = 'sex',hue='pclass',data=df)


plt.show()

In [23]: sns.countplot(x = 'sex',hue='adult_male',data=df)

Out[23]: <Axes: xlabel='sex', ylabel='count'>

In [24]: df1 = sns.load_dataset('iris')

In [25]: df1

Out[25]: sepal_length sepal_width petal_length petal_width species

0 5.1 3.5 1.4 0.2 setosa

1 4.9 3.0 1.4 0.2 setosa

2 4.7 3.2 1.3 0.2 setosa

3 4.6 3.1 1.5 0.2 setosa

4 5.0 3.6 1.4 0.2 setosa

... ... ... ... ... ...

145 6.7 3.0 5.2 2.3 virginica

146 6.3 2.5 5.0 1.9 virginica

147 6.5 3.0 5.2 2.0 virginica

148 6.2 3.4 5.4 2.3 virginica

149 5.9 3.0 5.1 1.8 virginica

150 rows × 5 columns

In [26]: #lineplot

In [27]: sns.lineplot(x='sepal_length',y='sepal_width',data=df1)
plt.show()

/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):
/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):

In [28]: #barplot

In [29]: df1

Out[29]: sepal_length sepal_width petal_length petal_width species

0 5.1 3.5 1.4 0.2 setosa

1 4.9 3.0 1.4 0.2 setosa

2 4.7 3.2 1.3 0.2 setosa

3 4.6 3.1 1.5 0.2 setosa

4 5.0 3.6 1.4 0.2 setosa

... ... ... ... ... ...

145 6.7 3.0 5.2 2.3 virginica

146 6.3 2.5 5.0 1.9 virginica

147 6.5 3.0 5.2 2.0 virginica

148 6.2 3.4 5.4 2.3 virginica

149 5.9 3.0 5.1 1.8 virginica

150 rows × 5 columns

In [31]: sns.barplot(x='species',y = 'sepal_width',data=df1)


plt.show()

In [32]: #box plot

In [33]: sns.boxplot(x='sepal_length',data=df1)
plt.show()

In [34]: sns.boxplot(x='species',y='sepal_length',data=df1)
plt.show()

In [35]: #plot boxplot for age col in titanic dataset

In [38]: plt.figure(figsize=(10,4))
sns.boxplot(x='age',data=df)
plt.show()

In [39]: sns.scatterplot(x='sepal_length',y='sepal_width',data=df1)
plt.show()

In [40]: #plot the histogram for age column in titanic dataset along with distribution plot

In [48]: sns.histplot(x='age',data=df,kde=True)
plt.show()

/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):

In [47]: sns.distplot(df['age'])
plt.show()

/var/folders/nn/9bkkh7612wg2c3gglt0zd9h40000gn/T/ipykernel_19528/2799180019.py:1: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

Please adapt your code to use either `displot` (a figure-level function with
similar flexibility) or `histplot` (an axes-level function for histograms).

For a guide to updating your code to use the new functions, please see
https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751

sns.distplot(df['age'])
/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):

In [49]: df2 = sns.load_dataset('tips')

In [50]: df2

Out[50]: total_bill tip sex smoker day time size

0 16.99 1.01 Female No Sun Dinner 2

1 10.34 1.66 Male No Sun Dinner 3

2 21.01 3.50 Male No Sun Dinner 3

3 23.68 3.31 Male No Sun Dinner 2

4 24.59 3.61 Female No Sun Dinner 4

... ... ... ... ... ... ... ...

239 29.03 5.92 Male No Sat Dinner 3

240 27.18 2.00 Female Yes Sat Dinner 2

241 22.67 2.00 Male Yes Sat Dinner 2

242 17.82 1.75 Male No Sat Dinner 2

243 18.78 3.00 Female No Thur Dinner 2

244 rows × 7 columns

In [51]: #PLOT countplot to show how many females are smokers

In [52]: sns.countplot(x='sex',hue='smoker',data=df2)
plt.show()

/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/categorical.py:641: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False t
o retain current behavior or observed=True to adopt the future default and silence this warning.
grouped_vals = vals.groupby(grouper)

In [53]: #plot count plot to show num of male and female visitors on each day
sns.countplot(x='sex',hue='day',data=df2)
plt.show()

/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/categorical.py:641: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False t
o retain current behavior or observed=True to adopt the future default and silence this warning.
grouped_vals = vals.groupby(grouper)

In [54]: #plot box plot for total_bill

In [55]: sns.boxplot(x='total_bill',data=df2)
plt.show()

In [59]: #plot the boxplot for total bill based on time(diner/lunch)

In [58]: sns.boxplot(x='total_bill',y='time',data=df2)
plt.show()

/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/categorical.py:641: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False t
o retain current behavior or observed=True to adopt the future default and silence this warning.
grouped_vals = vals.groupby(grouper)

In [60]: #plot the histogram for totalbill

In [61]: sns.histplot(x='total_bill',data=df2,kde=True)

/Users/satyakumarpalli/anaconda3/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instea
d.
with pd.option_context('mode.use_inf_as_na', True):
Out[61]: <Axes: xlabel='total_bill', ylabel='Count'>

In [ ]:

You might also like