0% found this document useful (0 votes)
22 views15 pages

Data Viz With Seaborn

Uploaded by

roman
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)
22 views15 pages

Data Viz With Seaborn

Uploaded by

roman
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/ 15

Data Visualization

seaborn

In [ ]:
import seaborn as sns
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

In [ ]:
data = sns.load_dataset("penguins")

In [ ]:
data[:5]

Out[ ]: s p e c i e s i s l a n d b i l l _ l e n g t h _ m m b i l l _ d e p t h _ m m f l i p p e r _ l e n gst eh _ m m

0 A d e l i eT o r g e r 39.1 18. 181.0 3750.0 Ma

1 A d e l i es e n 39.5 7 186.0 3800.0Fema

2 A d e l i eT o r g e r 40.3 17. 195.0 3250.0Fema

3 A d e l i es e n NaN 4 aN
N NaN NaN Na

4 A d e l i eT o r g e r 36.7 8.3
19 193.0 3450.0Fema

sen 0

In [ ]: Torger
data.shape
sen
Out[ ]:(344, 7) Torger

sen
In [ ]:
# Set the Seaborn theme
sns.set_theme()

# Set the dpi (dots per inch) value of the graphs to 300
sns.set(rc={"figure.dpi": 300})
# Define the width and height of the graphs in inches. Here, width is set to
sns.set(rc={"figure.figsize": (6, 3)})

In [ ]:
# Scatter plot
scatter = sns.scatterplot(x="bill_length_mm", y="bill_depth_mm", data=data, h
scatter.set_title("Bill Length vs Bill Depth")

Out[ ]:Text(0.5, 1.0, 'Bill Length vs Bill Depth')

By: lakshmanan M

1/13
seaborn

In [ ]:
sns.histplot(x= "flipper_length_mm" , data=data)
#sns.set_theme(style='dark')

Out[ ]:<Axes: xlabel='flipper_length_mm', ylabel='Count'>

In [ ]:
sns.histplot(y= "flipper_length_mm" , data=data)

Out[ ]:<Axes: xlabel='Count', ylabel='flipper_length_mm'>

By: lakshmanan M

2/13
seaborn

In [ ]:
sns.histplot(x= "flipper_length_mm" , data=data,binwidth=3)

Out[ ]:<Axes: xlabel='flipper_length_mm', ylabel='Count'>

In [ ]:
sns.histplot(x= "flipper_length_mm" , data=data,binwidth=3,kde=True)

Out[ ]:<Axes: xlabel='flipper_length_mm', ylabel='Count'>

By: lakshmanan M

3/13
seaborn

In [ ]:
sns.histplot(x= "flipper_length_mm" , data=data,binwidth=3,kde=True,hue="spec

Out[ ]:<Axes: xlabel='flipper_length_mm', ylabel='Count'>

In [ ]:
# Bar plot

bar = sns.barplot(x="species", y="flipper_length_mm", data=data, palette="Set

/var/folders/26/pvvz5dxx7lb978b1_d113_r40000gn/T/ipykernel_4463/3284859643.p
y:3: FutureWarning:
Passing `palette` without assigning `hue` is deprecated and will be removed i
n v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the sa
me effect.

bar = sns.barplot(x="species", y="flipper_length_mm", data=data, palette="S


et2")

By: lakshmanan M

4/13
seaborn

In [ ]:
bar = sns.barplot(x="species", y="flipper_length_mm", data=data,hue="sex")

In [ ]:
box = sns.boxplot(x="species", y="flipper_length_mm", data=data, palette="Set
box.set_title("Flipper Length by Species")

/var/folders/26/pvvz5dxx7lb978b1_d113_r40000gn/T/ipykernel_4463/345476460.py:
1: FutureWarning:
Passing `palette` without assigning `hue` is deprecated and will be removed i
n v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the sa
me effect.

box = sns.boxplot(x="species", y="flipper_length_mm", data=data, palette="S


et3")
Out[ ]:Text(0.5, 1.0, 'Flipper Length by Species')

By: lakshmanan M

5/13
seaborn

In [ ]:
box = sns.boxplot(x="species", y="flipper_length_mm", data=data, palette="Set
box.set_title("Flipper Length by Species") # Grafik başlığı

Out[ ]:Text(0.5, 1.0, 'Flipper Length by Species')

In [ ]:
sns.violinplot(x="species",y="flipper_length_mm",data=data)

Out[ ]:<Axes: xlabel='species', ylabel='flipper_length_mm'>

By: lakshmanan M

6/13
seaborn

In [ ]:
sns.violinplot(x="species",y="flipper_length_mm",data=data,hue="sex")

Out[ ]:<Axes: xlabel='species', ylabel='flipper_length_mm'>

In [ ]:
grid = sns.FacetGrid(data, col="island", row="sex", palette="Set2")

By: lakshmanan M

7/13
seaborn

In [ ]:
sns.FacetGrid(data,col="island",row="sex").map(sns.histplot,"flipper_length_m

Out[ ]:<seaborn.axisgrid.FacetGrid at 0x14f9f04f0>

In [ ]:
sns.FacetGrid(data,col="island",row="sex").map(sns.distplot, "flipper_length_

/Users/onurgumus/Desktop/Python ile Projeler/seaborn/.venv/lib/python3.10/sit


e-packages/seaborn/axisgrid.py:854: UserWarning

By: lakshmanan M

8/13
seaborn
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
func(*plot_args, **plot_kwargs)
/Users/onurgumus/Desktop/Python ile Projeler/seaborn/.venv/lib/python3.10/sit
e-packages/seaborn/axisgrid.py:854: 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
func(*plot_args, **plot_kwargs)
/Users/onurgumus/Desktop/Python ile Projeler/seaborn/.venv/lib/python3.10/sit
e-packages/seaborn/axisgrid.py:854: 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
func(*plot_args, **plot_kwargs)
/Users/onurgumus/Desktop/Python ile Projeler/seaborn/.venv/lib/python3.10/sit
e-packages/seaborn/axisgrid.py:854: 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
func(*plot_args, **plot_kwargs)
/Users/onurgumus/Desktop/Python ile Projeler/seaborn/.venv/lib/python3.10/sit
e-packages/seaborn/axisgrid.py:854: 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
func(*plot_args, **plot_kwargs)
/Users/onurgumus/Desktop/Python ile Projeler/seaborn/.venv/lib/python3.10/sit
e-packages/seaborn/axisgrid.py:854: 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
func(*plot_args, **plot_kwargs)

Out[ ]:<seaborn.axisgrid.FacetGrid at 0x14f4c62f0>

By: lakshmanan M

9/13
seaborn

In [ ]:
sns.pairplot(data,hue="species",height=3)

Out[ ]:<seaborn.axisgrid.PairGrid at 0x14fa59d20>

By: lakshmanan M

10/13
seaborn

In [ ]:
sns.pairplot(data,hue="species",height=3,diag_kind="hist")

Out[ ]:<seaborn.axisgrid.PairGrid at 0x28c3472e0>

By: lakshmanan M

11/13
seaborn

In [ ]:
from sklearn.preprocessing import LabelEncoder

label_encoder = LabelEncoder()
data["species_encoded"] = label_encoder.fit_transform(data["species"])
# Select numeric columns only for correlation analysis
numeric_data = data.select_dtypes(include=['float64', 'int64'])
# Create heatmap of correlations using numeric data
sns.heatmap(numeric_data.corr())

Out[ ]:<Axes: >

By: lakshmanan M

12/13
seaborn

In [ ]:
# Create heatmap of correlations using numeric data
sns.heatmap(numeric_data.corr(), annot=True)

Out[ ]:<Axes: >

By: lakshmanan M

13/13
Presented by Lakshmanan M

Thank you
very much!

By: lakshmanan M

You might also like