1.2 KiB
1.2 KiB
A8 - Data Visualization-1
✅ Tested and working as intended.
Pre-requisites
- Install required libraries:
seaborn&matplotlib
pip install matplotlib seaborn
Code blocks
- Import libraries:
import seaborn as sns
from matplotlib import pyplot as plt
- Load built-in dataset:
df=sns.load_dataset('titanic')
df.head()
- Dist plot for age:
plt.figure(figsize=(6,4))
sns.displot(df['age']) # Use sns.distplot(df['age']) for older versions of seaborn library
plt.show()
- Box plot:
plt.figure(figsize=(5,3))
bp = sns.boxplot(x='class',y='age',palette='pastel',data=df)
plt.show()
df.describe().transpose()
- Violin plot:
plt.figure(figsize=(5,4))
vp = sns.violinplot(x='class',y='age',palette='rainbow',data=df)
plt.show()
- Hist plot:
plt.figure(figsize=(5,4))
pq = sns.histplot(x='fare',bins=10,data=df,hue='survived',kde=False)
for i in pq.containers:
pq.bar_label(i)
plt.show()
- Scatter plot:
plt.figure(figsize=(5,4))
st=sns.scatterplot(x='age',y='fare',data=df)
plt.show()
- Scatter plot:
plt.figure(figsize=(5,4))
kl=sns.scatterplot(x='age',y='fare',data=df,hue='survived')
plt.show()