Matplotlib Tutorial: Complete 2-Day Roadmap to Master Data Visualization in Python
Nivesh Bansal

Nivesh Bansal @niveshbansal07

About: I'm Nivesh, a coding learner focused on Python, web development, and AI. I explore daily AI use and prompt interaction to boost skills and innovate through code and real-world smart solutions.

Location:
Muzaffarnagar, Uttar pradesh
Joined:
May 5, 2025

Matplotlib Tutorial: Complete 2-Day Roadmap to Master Data Visualization in Python

Publish Date: Aug 24
4 0

Matplotlib: 2-Day Beginner → Master Roadmap

Beginner-friendly roadmap to master Python’s Matplotlib in just 2 days. Covers essential plots, styling, layouts, and exporting, with mini-tasks to reinforce learning.

🔗 Live Demo

Check out the project here:
Live Demo
Source Code

How to Use This Roadmap

  • Follow Day 1 then Day 2.
  • Each block has Topic, Why, Key Functions, and a Mini-Task.
  • Use the OO API (fig, ax = plt.subplots()) from the start.
  • Practice with tiny arrays or a simple CSV so you focus on visuals, not data wrangling.

Day 1 — Foundations & Core Plots

Block Topic Why it matters Key Functions Mini-Task
1 Setup & Basics OO gives full control import matplotlib.pyplot as plt
fig, ax = plt.subplots()
Create an empty figure & set a title.
2 Line Plots Show trends over x ax.plot(x, y)
ax.legend()
Plot 2 lines with legend.
3 Scatter Plots Show relationships ax.scatter(x, y)
ax.grid(True)
Scatter with grid & labels.
4 Bar Charts Compare categories ax.bar(cats, vals)
ax.barh(...)
Make vertical & horizontal bars.
5 Histograms Show distribution ax.hist(x, bins=20) Compare bins=10 vs bins=30.
6 Box / Violin Plots Spread & outliers ax.boxplot(data) Boxplot of 3 groups.
7 Pie / Donut Quick share % (rarely) ax.pie(vals, labels=...) Create a donut chart.
8 Annotations & Text Highlight key points ax.annotate('peak', xy=(...)) Annotate max point with arrow.
9 Legends/Ticks/Spines Professional polish ax.legend(), ax.set_xticks() Rotate ticks & move legend.
10 Saving Figures Share results fig.tight_layout(), fig.savefig('plot.png') Export PNG & PDF (300dpi).

Day 2 — Layouts, Scales, Images, Advanced

Block Topic Why it matters Key Functions Mini-Task
1 Subplots & Layouts Dashboards plt.subplots(2,2) 2×2 dashboard.
2 Dual/Secondary Axes Compare scales ax.twinx() Temp+Rain plot.
3 Scales & Limits Reveal patterns ax.set_xscale('log') Linear vs log y.
4 Colormaps & Bars Encode magnitude im=ax.imshow(A)
fig.colorbar(im)
Heatmap w/colorbar.
5 Images & Heatmaps 2D data ax.imshow(A)
ax.contourf(...)
Imshow + contour.
6 Error bars Show uncertainty ax.errorbar(x, y, yerr=err) Line + CI band.
7 Time Series Dates formatting mdates.DateFormatter('%b %Y') Monthly data plot.
8 3D Basics Surfaces ax.plot_surface(X,Y,Z) Simple 3D.
9 Styling & Themes Consistency plt.style.use('ggplot') Apply theme + font.
10 Export like a Pro Quality output fig.savefig('plot.svg') Save SVG + transparent PNG.

Beginner Templates

Line + Scatter

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(6,4))
ax.plot(x, y, label='Line', marker='o')
ax.scatter(x, y2, label='Scatter', alpha=0.7)

ax.set(title='My Plot', xlabel='X', ylabel='Y')
ax.legend(); ax.grid(True, linestyle=':')

fig.tight_layout()
fig.savefig('plot.png', dpi=300)

Heatmap + Colorbar

im = ax.imshow(A, cmap='viridis', aspect='auto')
fig.colorbar(im, ax=ax)
ax.set(title='Heatmap')

Mini Projects

  • Day 1 Dashboard: 2×2 subplots (line, scatter, bar, hist). Add titles, legend, grid, and export PNG.
  • Day 2 Story: Heatmap w/colorbar, line+CI band, date-xaxis plot. Save transparent PNG + SVG.

Common Mistakes & Fixes

  • Using only plt.plot → Use OO API (fig, ax = plt.subplots()).
  • Overlapping labels → fig.tight_layout() or bbox_inches='tight'.
  • Bad colors → Use viridis, magma, cividis.
  • Too many pie slices → Use bar chart.
  • Hidden patterns → Try log scale (ax.set_yscale('log')).

2-Day Practice Plan

  1. Re-type each example (don’t copy-paste). Change 1 param, see result.
  2. Build a 2×2 dashboard twice: random data & small CSV.
  3. Recreate Day 2 plots with different styles & colormaps.

🔗 Live Demo

Check out the project here:
Live Demo
Source Code

Comments 0 total

    Add comment