PYTHON FOR DATA SCIENCE: FROM ARRAYS TO ANALYSIS / L07SEABORN: STATISTICAL DATA VISUALIZATION
课程 · 10 · 07 / 10
LESSON 07 · INTERMEDIATE · 60 MIN · ◆ 2 INSTRUMENTS

Seaborn: Statistical Data Visualization

Elevate your visualizations with seaborn. Create beautiful statistical graphics with minimal code: distributions, relationships, and categorical plots.

TIP

Learning Objectives: After this lesson, you'll create beautiful statistical graphics with minimal code using seaborn—distributions, relationships, categorical comparisons, and styled presentations.

Why Seaborn?

Seaborn is built on matplotlib but provides a high-level interface for creating attractive statistical graphics. What takes 10 lines in matplotlib often takes 1 line in seaborn.

FIG. 02Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 02Interactive Python code execution environment

Setting Up Seaborn

FIG. 04Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 04Interactive Python code execution environment

Distribution Plots

Understanding data distributions is fundamental to data analysis.

Histograms and KDE

FIG. 06Graph Plotter
INTERACTIVE
LOADING INSTRUMENT
Fig. 06Interactive plotting tool for visualizing data and relationships
FIG. 08Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 08Interactive Python code execution environment

Box Plots and Violin Plots

FIG. 10Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 10Interactive Python code execution environment

Relationship Plots

Explore relationships between variables.

Scatter Plots with Regression

FIG. 12Graph Plotter
INTERACTIVE
LOADING INSTRUMENT
Fig. 12Interactive plotting tool for visualizing data and relationships
FIG. 14Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 14Interactive Python code execution environment

Pair Plots

Visualize relationships between all pairs of variables:

FIG. 16Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 16Interactive Python code execution environment

Heatmaps

Visualize matrices and correlations:

FIG. 18Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 18Interactive Python code execution environment

Categorical Plots

Compare categories effectively.

Bar Plots with Error Bars

FIG. 20Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 20Interactive Python code execution environment

Count Plots

FIG. 22Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 22Interactive Python code execution environment

Strip and Swarm Plots

Show individual data points:

FIG. 24Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 24Interactive Python code execution environment

Combining Plots

FIG. 26Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 26Interactive Python code execution environment

FacetGrid: Multiple Subplots

Create a grid of plots based on data subsets:

FIG. 28Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 28Interactive Python code execution environment

Complete Example: EDA Dashboard

FIG. 30Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 30Interactive Python code execution environment

Key Takeaways

Distribution plots: histplot(), kdeplot(), boxplot(), violinplot()

Relationship plots: scatterplot(), regplot(), pairplot(), heatmap()

Categorical plots: barplot(), countplot(), stripplot(), swarmplot()

FacetGrid: Create grids of plots by data subsets

Styling: set_theme(), color palettes, context settings

Integration: Works seamlessly with pandas DataFrames

Connections: Seaborn in Practice

🔗 Connection to Statistics

Statistical ConceptSeaborn Plot
Distributionhistplot(), kdeplot()
Central tendencybarplot() (shows mean)
Spreadboxplot(), violinplot()
Correlationheatmap(), pairplot()
Regressionregplot(), lmplot()

🔗 When to Use Which Plot

QuestionPlot Type
What's the distribution?histogram, KDE, box
Compare categories?bar, count, box
Relationship between 2 vars?scatter, regression
All pairwise relationships?pairplot
Matrix of values?heatmap

Practice Exercises

Exercise 1: Complete Visualization

FIG. 32Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 32Interactive Python code execution environment

Next Steps

Now you're ready for Exploratory Data Analysis (EDA)—a systematic approach to understanding data by combining all the techniques you've learned.


Ready to explore real datasets? EDA is next!


Further Reading

Visual Galleries

Official Docs

Tutorials

Modern Declarative Alternatives

  • Altair — Vega-Lite-based grammar of graphics. Most principled "declarative viz" library in Python.
  • plotnineggplot2 ported to Python. If you came from R, start here.

Books

  • Book: Storytelling with Data — Cole Nussbaumer Knaflic. The why of visualization.
  • Book: Fundamentals of Data Visualization — Claus Wilke (free online). Library-agnostic; required reading for anyone making serious charts.