Plotting with Seaborn:

  • Seaborn is a plotting package that leverages the power of Matplotlib, but specializes and refines that interface to support visualization of tabular data and their statistical properties.
  • By convention, seaborn is imported as sns, a module that contains a variety of different plotting functions, as outlined here.

Seabornโ€™s Datasets:

  • The seaborn package contains some sample datasets that can be loaded using the sns.load_dataset function.
    • If you want to find out what datasets are available, you can call sns.get_dataset_names().
  • For example, the tips dataset contains information about the total bill.
python
1import seaborn as sns
2tips = sns.load_dataset("tips")
3sns.set_theme(style="darkgrid")
4tips.head()

Output:

total_billtipsexsmokerdaytimesize
16.991.01FemaleNoSunDinner2
10.341.66MaleNoSunDinner3
21.013.50MaleNoSunDinner3
23.683.31MaleNoSunDinner2
24.593.61FemaleNoSunDinner4

Visualizing Tips vs. Total Bill with Seaborn:

  • There are several ways to draw a scatter plot in seaborn, including the relplot() function.
    • The relplot() function is a figure-level function for visualizing statistical relationships using two common approaches: scatter plots and line plots.
python
5tips = sns.load_dataset("tips")
6sns.relplot(data=tips, x="total_bill", y="tip")

Output:

Seaborn scatter plot using relplot() showing tip amount vs total bill from the tips dataset