Skip to content
Tutorials Center
My learning

Topics

Matplotlib Tutorial

Learn Matplotlib step by step: 57 lessons in 10 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Matplotlib? Meet Matplotlib, Python's foundational plotting library. Learn what it does, how a figure becomes pixels, how it fits with NumPy, pandas and seaborn.
  2. 2 Installing Matplotlib and Using Jupyter Install Matplotlib with pip in a virtual environment, test it, choose a backend, use %matplotlib inline or widget in Jupyter, and fix plots that do not show up.
  3. 3 Your First Plot Draw your first Matplotlib line plot from Python lists and NumPy arrays, add a title and axis labels, and learn the two ways to call plt.plot.
  4. 4 Anatomy of a Figure Learn the names of every part of a Matplotlib chart: Figure, Axes, Axis, ticks, spines, legend and Artists, and why Axes is not the same as axis.
  5. 5 pyplot vs the Object-Oriented API Understand Matplotlib's two interfaces: the quick pyplot state machine and the explicit fig, ax = plt.subplots() style, and why the second is recommended.
  6. 6 Figure Size, DPI and Layout Control Matplotlib figure size with figsize and dpi, see how they become pixels, and fix clipped labels with constrained or tight layout and margins.

Line Plots and Basic Styling

  1. 7 Line Plots in Depth Go beyond one line: plot several series, functions and NumPy data, break lines with NaN, draw step plots, shade with fill_between and use dates on x.
  2. 8 Colors, Line Styles and Markers Control how lines look in Matplotlib: named colors, hex codes, RGB tuples, the C0-C9 cycle, line styles, markers, format strings, alpha and zorder.
  3. 9 Colormaps and Color Normalization Choose the right Matplotlib colormap, understand why viridis beats jet, and control the mapping with Normalize, LogNorm, TwoSlopeNorm and colorbars.
  4. 10 Titles, Labels, Text and Math Add titles, axis labels and free text to Matplotlib charts, control font size, weight and family, rotate labels, and write formulas with mathtext.
  5. 11 Limits, Scales and Aspect Control what part of your data Matplotlib shows: xlim and ylim, margins, log and symlog scales, inverted axes, equal aspect, secondary and twin axes.
  6. 12 Ticks, Locators and Formatters Take control of Matplotlib tick marks: set_xticks, tick labels, MultipleLocator, MaxNLocator, FuncFormatter, percent and currency labels, minor ticks.
  7. 13 Legends and Grids Add and place Matplotlib legends, move them outside the axes, build custom handles with Line2D and Patch, style major and minor grids, and use figure legends.

Core Chart Types

  1. 14 Bar Charts Draw bar charts with Matplotlib: bar and barh, grouped and stacked bars, error bars, bar_label, sorting and why bars must start at zero.
  2. 15 Scatter Plots Draw scatter plots in Matplotlib: scatter vs plot, size and color encodings, alpha for overplotting, bubble charts, colorbars and a polyfit trend line.
  3. 16 Histograms and Distributions Learn Matplotlib histograms: choosing bins, density, cumulative and stacked histograms, overlays, histtype, hist2d and hexbin, and bin-width pitfalls.
  4. 17 Box Plots and Violin Plots Draw and read box plots and violin plots in Matplotlib: quartiles, whiskers, fliers, notches, grouped boxes, and when each chart can mislead.
  5. 18 Pie, Donut and Stacked Area Charts Make pie and donut charts with Matplotlib (autopct, explode, wedgeprops), plus stackplot and stairs, and learn better part-to-whole alternatives.
  6. 19 Heatmaps and Images Draw heatmaps and images in Matplotlib with imshow and pcolormesh, annotate cells, plot a correlation matrix, and add contour, quiver and streamplot.
  7. 20 Error Bars and Uncertainty Show uncertainty honestly in Matplotlib with errorbar, asymmetric errors, fill_between bands, a bootstrap interval, eventplot and stem, all runnable live.
  8. 21 Broken Bars, matshow, spy, tricontour and triplot Learn five specialist Matplotlib charts: broken_barh timelines, matshow and spy for matrices, and tricontour, tricontourf and triplot for scattered points.

Subplots and Layouts

  1. 22 Multiple Subplots Put several charts in one Matplotlib figure with plt.subplots, index the axes array, share axes, hide empty panels, add a suptitle and control spacing.
  2. 23 GridSpec and subplot_mosaic Build uneven Matplotlib layouts with GridSpec, spanning rows and columns, width_ratios, subplot_mosaic strings, nested grids, inset axes and a dashboard.
  3. 24 Shared, Twin and Secondary Axes Use sharex and sharey, twinx for two y scales, and secondary_yaxis with a conversion function in Matplotlib, and learn when dual axes mislead readers.

Annotation and Polish

  1. 25 Annotations and Arrows Guide the reader's eye with ax.annotate, arrowprops, coordinate systems, axhline, axvline, axvspan, boxed text and direct labels on the last point.
  2. 26 Shapes, Patches and Custom Drawing Draw custom shapes in Matplotlib with Rectangle, Circle, Ellipse, Polygon, Arc and FancyArrow, add_patch, PatchCollection, transforms, clipping and diagrams.
  3. 27 Styles, rcParams and Themes Give every chart the same look. Learn plt.style.use, rcParams, rc_context, color cyclers, dark backgrounds and your own style dictionary.
  4. 28 Designing Clear Charts Make charts people understand at a glance. Learn data-ink, picking the right chart, direct labels, accessible color and before/after redesigns.

Working with Data

  1. 29 Plotting NumPy and pandas Data Turn arrays and DataFrames into charts. Use meshgrid, DataFrame columns, df.plot with ax=, groupby loops, pivot tables and datetime indexes.
  2. 30 Dates and Time Series Charts Plot dates on the x axis with datetime and pandas, format ticks with mdates, add rolling averages, shade date ranges and handle gaps.
  3. 31 Seaborn-Style Recipes in Pure Matplotlib Rebuild pair plots, KDE curves, regression plots, strip plots and joint plots with Matplotlib, SciPy and GridSpec, and see what seaborn shortens.
  4. 32 Statistical Plots Recipes Draw QQ plots, residual plots, ECDFs, density curves, correlation and confusion heatmaps, ROC curves and learning curves with Matplotlib.
  5. 33 Plotting Sound and Spectrograms Plot a sound wave and its spectrum with Matplotlib and NumPy, then draw a spectrogram with specgram: sample rate, window size, overlap, decibels and colour limits.

3D, Animation and Advanced

  1. 34 3D Plots Draw 3D lines, scatter clouds, surfaces, wireframes and contours with projection=3d, set the camera with view_init, and know when 3D hurts readability.
  2. 35 Polar Plots and Radar Charts Use projection=polar for angle and radius data: rose and wind charts, polar bars, circular histograms, log radius and a radar chart built from polar axes.
  3. 36 Maps with Matplotlib, GeoPandas and Cartopy Draw maps in Python: longitude and latitude as x and y, fixing map distortion, projections, choropleth maps with polygons, GeoPandas, and Cartopy for real coastlines.
  4. 37 Animation Concepts Understand how FuncAnimation and ArtistAnimation work: update functions, frames, interval and blit, saving GIF or MP4, and previewing frames as a filmstrip.
  5. 38 Interactivity and Widgets Learn matplotlib backends, mpl_connect events, Slider, Button and CheckButtons, picking, and the zoom toolbar, with simulated events that render static frames.
  6. 39 Transforms and the Artist Layer Learn data, axes, figure and display coordinates, transData and blended transforms, custom Artists, collections, zorder and path effects, and why artists drive speed.

Saving and Production

  1. 40 Saving Figures Export Matplotlib figures with savefig: formats, dpi, bbox_inches tight, transparent backgrounds, BytesIO and base64, metadata, file size and print-ready output.
  2. 41 Plotting Large Data Fast Make slow Matplotlib charts fast: aggregate with hexbin and hist2d, downsample, rasterize dense layers, set path chunking, close figures and profile what is slow.
  3. 42 Reproducible and Automated Charts Turn one-off Matplotlib code into repeatable pipelines: chart functions, loops over many datasets, style presets, headless servers, image tests and alt text.
  4. 43 Pitfalls and Debugging Fix the Matplotlib problems everyone hits: overlapping figures, leaking state, cut-off labels, axes vs axis, odd scatter colors, mutable defaults and warnings.
  5. 44 The Matplotlib Ecosystem See how seaborn, plotly, bokeh, altair, plotnine, cartopy, mplfinance and pandas plotting relate to Matplotlib, and how to choose the right tool.

Projects

  1. 45 Project: Sales Dashboard Build a one-page sales dashboard in Matplotlib with subplot_mosaic: a KPI strip, a trend line, a regional bar chart, a share donut and annotations.
  2. 46 Project: Weather Station Report Build a climate report in Matplotlib from a year of synthetic weather data: a dual-axis climograph, monthly boxplots, a day-by-month heatmap and seasonal shading.
  3. 47 Project: Exploratory Data Report Build an exploratory data report in Matplotlib and pandas: histogram grid, correlation heatmap, scatter matrix, outlier highlighting and a one-page report function.
  4. 48 Project: Model Diagnostics Plots Plot a scikit-learn classifier with Matplotlib: decision boundary, confusion matrix, ROC and precision-recall curves, feature importance and a learning curve.
  5. 49 Project: Physics and Math Visualizer Visualize physics and math with Matplotlib: projectile paths, a pendulum phase portrait, Lissajous curves, the Mandelbrot set, a streamplot and a filmstrip.
  6. 50 Project: Infographic Poster Design an infographic poster with Matplotlib: draw a layout with patches and text, add gradient backgrounds, icon shapes, a donut, a timeline, then export it.
  7. 51 Project: Visualizing Sorting Algorithms Record every step of bubble, insertion, merge and quick sort, draw the steps as bar-chart filmstrips, compare operation counts with Matplotlib, and animate on your computer.
  8. 52 Project: A 3D Sine Wave Surface Build a rippling 3D sine wave surface in Matplotlib: meshgrid maths, travelling waves as a filmstrip, two-source interference, camera angles and an animation for your computer.
  9. 53 Project: Visualizing a Pandemic Time Series Visualize daily case counts for several countries with Matplotlib and pandas: weekly reporting patterns, 7-day rolling averages, cumulative totals, per-capita and log-scale charts.
  10. 54 Project: Analysing Used Car Prices Chart the drivers of used-car prices with Matplotlib: histograms, scatter plots with trend lines, box plots by brand, grouped bars, a depreciation fit and a polished summary figure.

Practice and Interview

  1. 55 Practice Exercises With Solutions Practice Matplotlib with 25 graded exercises on line plots, bars, histograms, subplots, annotations, styling, dates and heatmaps. Every solution runs live.
  2. 56 Matplotlib Interview Questions Prepare for data and Python interviews with 20 Matplotlib questions: pyplot vs OO, Figure vs Axes, savefig and dpi, shared axes, big data, backends. Runnable demos.
  3. 57 Matplotlib Cheat Sheet A one-page Matplotlib cheat sheet with tables for the object-oriented pattern, chart calls, labels, ticks, legends, subplots, styles, saving and common fixes.