#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
📈 FREE · 34 SNIPPETS

Matplotlib Cheat Sheet: Charts in Python, Fast

The Matplotlib calls you need to make a clear chart, using the fig, ax style that scales to real projects.

  • 📊 Every common chart
  • 🏷️ Labels and ticks
  • 🧩 Subplots

How to use the Matplotlib Cheat Sheet

  1. 1. Search or browseType what you want to do, or pick one section of the Matplotlib cheat sheet.
  2. 2. CopyEvery entry has its own Copy button, so it goes straight into your editor or notes.
  3. 3. DownloadSave the whole Matplotlib cheat sheet as plain text or Markdown for offline revision.

What's in it

Snippets use the object-oriented style: create fig, ax = plt.subplots() once and call methods on ax. Variables x, y and data stand for your own arrays. The 34 snippets are organised into 8 sections: Setup, Line & scatter, Bar & pie, Distributions, Labels & titles, Axes & ticks, Several plots, Style.

Every snippet was run with Matplotlib 3.x on sample data (non-interactive backend) without errors.

Example

A clean bar chart takes four lines: fig, ax = plt.subplots(figsize=(8, 4)), ax.bar(["A", "B", "C"], [5, 7, 3]), ax.set_title("Monthly sales"), then ax.spines[["top", "right"]].set_visible(False) to drop the box. Save it with fig.savefig("chart.png", dpi=200, bbox_inches="tight") so long labels aren't cut off.

Tips for using it

  • Pass label= on each series, then call ax.legend(); a legend with no labels shows nothing.
  • Use barh for long category names instead of rotating labels by 90 degrees.
  • In a loop that saves hundreds of charts, call plt.close(fig) after each save to keep memory flat.

A quick look, one entry per section

  • Setup: import matplotlib.pyplot as plt (the usual imports)
  • Line & scatter: ax.plot(x, y, label="Sales") (line chart)
  • Bar & pie: ax.bar(["A", "B", "C"], [5, 7, 3]) (vertical bar chart)
  • Distributions: ax.hist(data, bins=20, edgecolor="white") (histogram)
  • Labels & titles: ax.set_title("Monthly sales") (title and axis labels)
  • Axes & ticks: ax.set_xlim(0, 10) (set axis limits)
  • Several plots: fig, axs = plt.subplots(2, 2, figsize=(8, 6)) (a grid of plots; index axs[row, col])
  • Style: plt.style.use("ggplot") (use a built-in style (see plt.style.available))

Search the box above for the rest of the Matplotlib entries, or download the full sheet.

Frequently asked questions

Which Matplotlib version?

The snippets were run with Matplotlib 3.x. Passing a list to ax.spines needs 3.4 or later; set_xticks with labels= needs 3.5 or later.

Should I use seaborn instead?

Seaborn is built on Matplotlib and is quicker for statistical charts. You still use these Matplotlib calls to fine-tune titles, ticks and layout.

Is the Matplotlib cheat sheet free?

Yes. You can search, read and copy every entry in the Matplotlib cheat sheet without signing up. The first time you download it, we ask once for your name and WhatsApp number; after that downloads and every other Uncodemy tool open straight away.

More free tools

See all free tools