Learnr

Learn Matplotlib

Python plotting from your first line chart to publication-ready figures.

Free to start. No credit card. Or browse all courses.

What's inside your Matplotlib course

A sample path Learnr builds for Matplotlib. Your real course adapts to your goal and level.

  1. Figures, axes and the two Matplotlib interfaces
  2. Core plot types: line, scatter, bar and histogram
  3. Labels, legends, ticks and annotations
  4. Subplots, shared axes and layout managers
  5. Color, colormaps, style sheets and rcParams
  6. Images, saving figures and plotting from pandas

Matplotlib is the plotting library underneath most of the Python data world. Seaborn, the pandas .plot method and many notebook charts all draw through it, so knowing it lets you fix any figure those tools produce. Its learning curve comes from having two interfaces: the quick pyplot state machine (plt.plot) and the explicit object-oriented style where you create a Figure and Axes and call methods on them. Once you see that every element on a chart is an object you can reach and change, it stops feeling arbitrary. Learnr builds a Matplotlib course in short lessons with code to read and predict, from one line chart to multi-panel figures.

How to learn Matplotlib, step by step

  1. Start with fig, ax = plt.subplots(). Write every chart in the object-oriented style from day one: ax.plot, ax.set_xlabel, ax.set_title. Mixing plt calls and ax calls is the main source of confusion, and the explicit style scales cleanly once you need more than one panel.
  2. Learn the anatomy of a figure. Study the labeled anatomy diagram in the official docs until you can name the Figure, Axes, Axis, tick locators, spines and legend. Then any customization becomes a question of which object owns that element.
  3. Match the plot type to the question. Use ax.plot for trends over time, ax.scatter for relationships, ax.bar for category comparisons and ax.hist for distributions. Recreate each with a small real dataset, such as daily temperatures, and adjust the histogram bins to see how shape changes.
  4. Build multi-panel figures. Make a 2 by 2 grid with plt.subplots(2, 2, sharex=True), loop over axes.flat, and pass layout="constrained" so labels stop overlapping. Add a figure-level suptitle and a single shared legend.
  5. Control style instead of fighting defaults. Set fonts and sizes once with rcParams or a style sheet, pick perceptually uniform colormaps like viridis for continuous data, and remove chart junk such as extra spines. Annotate one key point with ax.annotate and an arrow.
  6. Practice by remaking real charts. Take charts from news articles and rebuild them, including the gallery examples on the Matplotlib site. Short daily exercises in a Learnr course keep the method names fresh while your rebuilds get closer to the originals.

What you'll learn

  • Create a figure and axes with plt.subplots and plot on them explicitly
  • Choose between line, scatter, bar, histogram and image plots for a dataset
  • Arrange several panels in a grid with shared axes and a clean layout
  • Customize ticks, labels, legends, colormaps and annotations
  • Export sharp figures with savefig at the right size and resolution

How long does it take to learn Matplotlib?

If you already write basic Python, a week or two of evenings gets you making clean standard charts. Multi-panel figures, custom styling and confident troubleshooting usually take 1 to 2 months of regular use. Real projects with messy data speed it up more than reading the API reference.

What you need before you start

Basic Python (lists, loops, functions, importing libraries) and ideally a little NumPy or pandas, since most data you plot will live in arrays or DataFrames. A Jupyter notebook is the easiest place to practice.

Common mistakes to avoid

  • Mixing plt.title and ax.set_title in one script, then wondering which axes a change landed on. Pick the explicit ax style and stick to it.
  • Leaving default figure sizes and saving at low resolution, so text is unreadable in a report. Set figsize and dpi deliberately in savefig.
  • Using a rainbow colormap like jet for continuous values, which creates false boundaries. Use viridis or another perceptually uniform map.

How Learnr builds your course

Type your topic

Tell Learnr you want to learn Matplotlib, or get as specific as you like.

Get a personalized course

Learnr instantly builds a full Matplotlib course tailored to your goal and skill level.

Learn and level up

Move through bite-sized lessons and interactive practice, earning XP and keeping your streak.

Matplotlib questions, answered

Should I learn Matplotlib or Seaborn first?

Seaborn gives nicer statistical charts with less code, but it returns Matplotlib objects. Learning the Matplotlib basics first means you can adjust any Seaborn chart instead of being stuck with its defaults.

Is Matplotlib still worth learning with interactive libraries around?

Yes. It remains the standard for static figures in papers, reports and scientific code, and many other libraries build on it. Interactive tools like Plotly are a good addition, not a replacement.

Why does my plot not show up?

In a plain Python script you need plt.show() at the end. In Jupyter, figures display automatically when the cell finishes. If you saved first and called show later, check that you did not close the figure.

Explore more courses

More data and ai courses

See all data and ai courses

Ready to learn Matplotlib?

Start your free, personalized Matplotlib course in seconds. It will be typed in and ready when you get there.

Start learning Matplotlib

Free to start. No credit card.