Data Viz With Seaborn
Data Viz With Seaborn
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
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")
By: lakshmanan M
1/13
seaborn
In [ ]:
sns.histplot(x= "flipper_length_mm" , data=data)
#sns.set_theme(style='dark')
In [ ]:
sns.histplot(y= "flipper_length_mm" , data=data)
By: lakshmanan M
2/13
seaborn
In [ ]:
sns.histplot(x= "flipper_length_mm" , data=data,binwidth=3)
In [ ]:
sns.histplot(x= "flipper_length_mm" , data=data,binwidth=3,kde=True)
By: lakshmanan M
3/13
seaborn
In [ ]:
sns.histplot(x= "flipper_length_mm" , data=data,binwidth=3,kde=True,hue="spec
In [ ]:
# Bar plot
/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.
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.
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ığı
In [ ]:
sns.violinplot(x="species",y="flipper_length_mm",data=data)
By: lakshmanan M
6/13
seaborn
In [ ]:
sns.violinplot(x="species",y="flipper_length_mm",data=data,hue="sex")
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
In [ ]:
sns.FacetGrid(data,col="island",row="sex").map(sns.distplot, "flipper_length_
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:
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:
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:
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:
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:
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)
By: lakshmanan M
9/13
seaborn
In [ ]:
sns.pairplot(data,hue="species",height=3)
By: lakshmanan M
10/13
seaborn
In [ ]:
sns.pairplot(data,hue="species",height=3,diag_kind="hist")
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())
By: lakshmanan M
12/13
seaborn
In [ ]:
# Create heatmap of correlations using numeric data
sns.heatmap(numeric_data.corr(), annot=True)
By: lakshmanan M
13/13
Presented by Lakshmanan M
Thank you
very much!
By: lakshmanan M