Skip to content

Instantly share code, notes, and snippets.

@JonnyCBB
Created September 23, 2018 18:37
Show Gist options
  • Save JonnyCBB/449fcd61ed3aa54e16f4d87f8bcd25bf to your computer and use it in GitHub Desktop.
Save JonnyCBB/449fcd61ed3aa54e16f4d87f8bcd25bf to your computer and use it in GitHub Desktop.
Creating a boxplot using matplotlib's standard boxplot function and Seaborn's boxplot function
import matplotlib.pyplot as plt
import seaborn as sns
tips = sns.load_dataset("tips") # Load data
fig, axs = plt.subplots(1, 2) # Create subplots
# Boxplot with matplotlib
tips_box = [tips.query('day == @day')['total_bill'] for day in tips.day.unique()]
axs[0].boxplot(tips_box, labels=tips.day.unique())
# Boxplot with Seaborn
sns.boxplot(x="day", y="total_bill", data=tips, ax=axs[1])
fig.suptitle('Boxplot', fontsize=18) #
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment