Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 38 ยท Getting Started

Introduction to Seaborn

Meet seaborn, the Python library for statistical graphics. See how it builds on Matplotlib and pandas, what it can draw, and how one line replaces dozens.

Seaborn is a Python library for drawing statistical graphics. You give it a table of data (a pandas DataFrame) and name the columns you care about; seaborn counts, groups, averages, estimates, and draws the result with sensible colors and labels. A scatter plot with a regression line, a violin plot per category, or a heatmap of correlations each takes one function call.

Seaborn does not replace Matplotlib. It sits on top of it: every seaborn plot is a Matplotlib figure, and you can polish it with ordinary Matplotlib code. Think of Matplotlib as the drawing engine and seaborn as the data-aware layer that decides what to draw. This lesson shows the big picture before the details.

What seaborn adds to Matplotlib

Matplotlib asks you to prepare the arrays yourself. To compare tips by day, you group the data, compute means, pick colors, loop over bars, and add a legend by hand. Seaborn lets you describe the plot in terms of your data instead:

  • Columns as arguments. You write x="day", y="tip", hue="sex" and seaborn maps each column onto an axis or a color.
  • Statistics built in. Bar heights can be means with confidence intervals, histograms can have density curves, scatter plots can have regression lines.
  • Good defaults. Themes, color palettes, legends, and axis labels come ready, and they are designed to be readable and colorblind-aware.
  • Multi-plot grids. One call can produce a whole grid of small charts, one per category.

Seaborn in the Python stack

NumPy Fast arrays hold the numbers.
pandas DataFrames hold the tidy table.
Matplotlib Draws figures, axes and lines.
seaborn Turns columns into statistical plots.

Seaborn imports all three and hides most of the plumbing.

1 / 2

Your first look

Seaborn is a pure-Python package. On this site the first run installs it in your browser with micropip, which takes a few seconds. On your own computer you would run pip install seaborn once and skip those two install lines.

The data below is a small, made-up restaurant table, generated with a fixed random seed so everyone sees the same numbers. Real projects load data from CSV files or databases, which a later lesson covers.

Python Your first seaborn plot

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the plot call aloud: scatterplot of tips, total_bill on x, tip on y, colored by time. Seaborn picked two colors, built the legend, and labeled both axes from the column names. The Matplotlib version needs a loop over the groups and a manual legend.

Seaborn compared with other tools

Task Matplotlib alone seaborn
Scatter plot colored by group Loop over groups, set colors, build legend One call with hue=
Mean per category with error bars Group, compute standard errors, draw bars and lines barplot does it
Histogram with a density curve Compute the KDE with SciPy and plot both histplot(kde=True)
Grid of plots by category Create subplots and loop col= or FacetGrid
Correlation matrix as colors imshow plus ticks and text heatmap(annot=True)

Seaborn is not the right tool for everything. For fully custom layouts, maps, 3D plots, or animations, use Matplotlib directly. For interactive web charts, look at a library such as Plotly. Seaborn shines for exploring and communicating results of tabular data.

A note about statistics

Many seaborn functions do more than draw: they summarize. A bar plot shows a mean and a confidence interval, a line plot aggregates repeated measurements, and a regression plot fits a model. These summaries are estimates, and seaborn labels them with shaded bands or error bars. the Statistical Estimation chapter later in the course explains how they are computed. For now, remember that a plot can contain a calculation, so know what each function does before you trust a picture.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does seaborn relate to Matplotlib?

    Seaborn calls Matplotlib to draw. You can customize any seaborn plot with normal Matplotlib commands.
  2. 2. What kind of input does seaborn work with best?

    You pass data= plus column names for x, y, hue and so on. Arrays and lists also work, but tables are the natural fit.
  3. 3. What does hue="time" do in a scatter plot?

    hue maps a column to color. Seaborn chooses the palette and builds the legend.
  4. 4. Which task is a poor fit for seaborn?

    Seaborn focuses on statistical plots of tabular data. 3D and maps are better done with Matplotlib or specialized libraries.

Summary

  • Seaborn is a statistical plotting library built on Matplotlib and pandas.
  • You describe plots with column names (x, y, hue), and seaborn handles statistics, colors, legends and labels.
  • Plot families: distributions, relational, categorical, matrix plots, and multi-plot grids.
  • Every result is a Matplotlib figure, so Matplotlib tweaks still work.
  • On this site the first run installs seaborn in your browser; locally you use pip install seaborn.

Next: Installing Seaborn and Your First Plots