Seaborn Statistical Charts

ECON 3209 · Week 5, Lecture 2 · Kerala Agricultural University

Department of Development Economics, KAU

Autumn 2026

Learning Outcomes

By the end of this lecture, you will be able to:

  1. Explain why seaborn is useful for statistical graphics
  2. Create distribution, boxplot, heatmap, and pairplot charts
  3. Read variation, outliers, and association from statistical plots
  4. Use seaborn with Kerala agricultural and banking examples
  5. Combine seaborn aesthetics with Matplotlib control

Why Seaborn?

  • Seaborn builds on Matplotlib but offers better default styling
  • It is especially strong for statistical visualisation
  • Many exploratory charts require fewer lines of code in seaborn
  • It works naturally with pandas DataFrames
  • Economists often use it for quick, informative exploratory analysis

A Distribution Plot

  • Historically, seaborn users often learned distplot
  • Newer versions prefer histplot(..., kde=True)
  • Both show the distribution and a smooth density curve
  • Distribution charts help detect skewness and spread

Boxplots for Spread and Outliers

  • The box shows the interquartile range
  • The line inside the box is the median
  • Points beyond the whiskers may be outliers
  • Boxplots help compare distributions across groups quickly

Heatmaps for Correlation Structure

  • Heatmaps are excellent for seeing many correlations at once
  • Colour intensity reveals stronger positive or negative association
  • Annotation helps when an audience needs exact values
  • Heatmaps are descriptive tools, not causal evidence

Pairplots for Many Relationships

  • Pairplots combine scatter plots and univariate distributions
  • They quickly reveal relationships, clusters, and scale differences
  • They are useful in early exploratory work on small-to-medium datasets
  • Large datasets may require sampling to stay readable

Seaborn Works Best with DataFrames

  • Seaborn usually expects “long” or tidy DataFrames
  • Column names become plot variables such as x, y, and hue
  • This makes code more expressive than passing many separate arrays
  • It also connects naturally to the pandas workflows from Week 4
  • Good data wrangling improves charting quality immediately

Reading Statistical Graphics Carefully

  • A pretty chart is not automatically informative
  • Ask what variable is being summarised and in what units
  • Distinguish between distribution shape, central tendency, and outliers
  • Correlation patterns can reflect scale or omitted factors
  • Use economic context to interpret, not just visual intuition

Visualisation should sharpen your questions before modelling — not replace careful econometric reasoning.

Combining Seaborn and Matplotlib

  • Seaborn handles style and statistical defaults elegantly
  • Matplotlib still gives fine-grained control over titles and axes
  • In practice, analysts often use both libraries together
  • This combination is powerful and flexible for teaching and research

Choosing Among Seaborn Charts

Use These When

  • Distribution plot: shape of one numeric variable
  • Boxplot: compare spread across groups
  • Heatmap: inspect many correlations

Also Remember

  • Pairplot: multi-variable exploration
  • Too many variables create clutter
  • Always label variables clearly

Exercise

Create a small DataFrame with a crop column and a numeric price column.

  1. Use seaborn to draw a boxplot of prices by crop.
  2. Add a title.
  3. End with plt.show().

Summary

  • ✅ seaborn provides attractive defaults for statistical graphics
  • ✅ Distribution plots, boxplots, heatmaps, and pairplots answer different questions
  • ✅ seaborn works especially well with pandas DataFrames
  • ✅ Statistical charts help reveal spread, outliers, and association
  • ✅ Matplotlib and seaborn are usually used together, not separately
  • ✅ Clear interpretation still matters more than visual polish alone

Next Lecture

Interactive Plots and Publication-Ready Figures

  • We will build multi-panel charts and improve formatting
  • You will learn saving options, annotations, and presentation standards
  • This turns exploratory plots into polished communication tools