# Load an example datasettips=sns.load_dataset('tips')
Plot Types
Scatter Plot
# Scatter plot with linear regressionsns.lmplot(x='total_bill',y='tip',data=tips)plt.show()
Line Plot
# Line plot with confidence interval shadingsns.lineplot(x='size',y='total_bill',data=tips)plt.show()
Bar Plot
# Bar plot with aggregationsns.barplot(x='day',y='total_bill',data=tips)plt.show()
Histogram
# Histogram with KDEsns.histplot(tips['total_bill'],kde=True)plt.show()
Box Plot
# Box plot with categoriessns.boxplot(x='day',y='total_bill',data=tips)plt.show()
Violin Plot
# Violin plot with categoriessns.violinplot(x='day',y='total_bill',data=tips)plt.show()
Heatmap
# Heatmap with annotationsflights=sns.load_dataset('flights')flights_pivot=flights.pivot('month','year','passengers')sns.heatmap(flights_pivot,annot=True,fmt='d')plt.show()
Pair Plot
# Pair plot with huesns.pairplot(tips,hue='sex')plt.show()
Joint Plot
# Joint plot with scatter and histogramssns.jointplot(x='total_bill',y='tip',data=tips,kind='scatter')plt.show()
Customizing Plots
Adding Titles and Labels
sns.boxplot(x='day',y='total_bill',data=tips)plt.title('Total Bill by Day')plt.xlabel('Day of the Week')plt.ylabel('Total Bill')plt.show()
importseabornassnsimportmatplotlib.pyplotasplt# Load the datasettips=sns.load_dataset('tips')# Set the stylesns.set_style('whitegrid')# Create a figure and a set of subplotsfig,axs=plt.subplots(2,2,figsize=(12,10))# Scatter plot with linear regressionsns.lmplot(x='total_bill',y='tip',data=tips,ax=axs[0,0])axs[0,0].set_title('Scatter Plot with Linear Regression')# Bar plot with aggregationsns.barplot(x='day',y='total_bill',data=tips,ax=axs[0,1])axs[0,1].set_title('Bar Plot')# Box plot with categoriessns.boxplot(x='day',y='total_bill',data=tips,ax=axs[1,0])axs[1,0].set_title('Box Plot')# Heatmap with annotationsflights=sns.load_dataset('flights')flights_pivot=flights.pivot('month','year','passengers')sns.heatmap(flights_pivot,annot=True,fmt='d',ax=axs[1,1])axs[1,1].set_title('Heatmap')# Show the plotsplt.tight_layout()plt.show()