Matplotlib Tutorial — Complete Guide to Data Visualization with Matplotlib

2 minute read

Welcome to the complete Matplotlib tutorial — your end-to-end guide to data visualization in Python. Whether you’re moving on from Excel charts, switching from R’s ggplot2, or building dashboards from Pandas DataFrames, this tutorial takes you from your first plt.plot() to publication-quality multi-panel figures.

Matplotlib Tutorial

12 Chapters ~85 Lessons Intermediate Level ~15 hours

What is Matplotlib?

Matplotlib is the foundational plotting library for Python — created by John Hunter in 2003 to bring MATLAB-style plotting to scientific Python. It powers almost every static chart you’ll ever see in a Jupyter notebook, a research paper, or a Python data dashboard.

  • Figure → Axes → Artist — a clean three-layer architecture
  • Two APIs — a quick plt.* state machine and a clean object-oriented fig, ax API
  • Universal output — PNG, PDF, SVG, EPS at any DPI you want
  • The substrate — Pandas .plot(), Seaborn, and most of scikit-learn’s diagnostics all render through Matplotlib

If NumPy and Pandas are how you compute, Matplotlib is how you show.


Tutorial Details

   
Level Intermediate
Chapters 12
Lessons ~85
Time to complete ~15 hours
Prerequisites Python Basics, NumPy fundamentals, basic Pandas
Python version 3.10+
Matplotlib version 3.7+ (most 3.5+ code works)

What You’ll Learn

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

  • Build every standard chart type — line, bar, scatter, histogram, pie, area
  • Use the OO API (fig, ax = plt.subplots()) confidently — the professional pattern
  • Customize every visual element: titles, ticks, legends, colors, colormaps
  • Construct multi-panel layouts with subplots, subplot2grid, and GridSpec
  • Add annotations, reference lines, LaTeX math text, and watermarks
  • Save publication-quality figures in PNG, PDF, and SVG at any DPI
  • Choose the right chart for any data story
  • Be fully prepared for Seaborn and Plotly

Prerequisites

You should be comfortable with:

  • Python basics: functions, lists, dictionaries, loops, list comprehensions
  • NumPy arrays: np.array, np.arange, np.linspace, np.random
  • Basic Pandas: loading a CSV into a DataFrame, selecting columns

If you need a refresher, start with our Python Basics Tutorial, then the NumPy Tutorial, and the Pandas Tutorial.


Chapters

# Chapter Topics
1 Introduction to Matplotlib History, architecture (Figure/Axes/Artist), installation, alternatives
2 pyplot Basics plt.plot, plt.show, plt.savefig, basic customization, Jupyter
3 Figure & Axes (OO API) fig, ax = plt.subplots(), figure props, axes methods, twin axes
4 Line Plots Basic line, multiple lines, styles & markers, fill_between
5 Bar & Horizontal Bar Charts ax.bar, ax.barh, grouped, stacked, value labels, error bars
6 Scatter Plots ax.scatter, color mapping, bubble charts, colorbar, overplotting
7 Histograms & Distribution Plots ax.hist, bins, density, cumulative, 2D histograms, hexbin
8 Pie Charts & Area Plots ax.pie, donut, fill_between, stackplot, chart selection guide
9 Customization Titles, ticks, legends, styles, rcParams, colors, colormaps
10 Subplots & Layouts subplots, shared axes, subplot2grid, GridSpec, tight layout
11 Annotations & Text ax.text, ax.annotate, reference lines, LaTeX, figure text
12 Practice Projects & Next Steps Sales dashboard, weather analysis, stock chart, publication figure

Learning Path

Python Basics  →  NumPy  →  Pandas  →  Matplotlib (you are here)  →  Seaborn  →  Plotly

Matplotlib is the substrate. Master it once, and every higher-level library (Seaborn, Pandas .plot, the diagnostic plots in scikit-learn) becomes easy to read, customize, and debug.


← All Python Tutorials Start Matplotlib Tutorial →

Updated: