100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Matplotlib Cheat Sheet

Matplotlib Cheat Sheet

Matplotlib plotting reference covering the object-oriented API, subplots, common chart types, and styling options for publication-ready figures.

1 PageBeginnerApr 5, 2026

Basic Plot

Object-oriented figure and axes API.

python
import matplotlib.pyplot as pltfig, ax = plt.subplots(figsize=(8, 5))ax.plot(x, y, label="sin(x)", color="tab:blue", linewidth=2)ax.set_xlabel("x")ax.set_ylabel("y")ax.set_title("Simple Line Plot")ax.legend()plt.savefig("plot.png", dpi=150, bbox_inches="tight")plt.show()

Subplots

Arrange multiple axes in a grid.

python
fig, axes = plt.subplots(2, 2, figsize=(10, 8), sharex=True)axes[0, 0].plot(x, y1)axes[0, 1].scatter(x, y2)axes[1, 0].bar(categories, values)axes[1, 1].hist(data, bins=30)fig.tight_layout()

Common Plot Types

Frequently used chart functions.

  • ax.plot- line chart
  • ax.scatter- scatter plot
  • ax.bar / ax.barh- vertical/horizontal bar chart
  • ax.hist- histogram of a distribution
  • ax.boxplot- box-and-whisker plot
  • ax.imshow- display an image or 2D array as a raster
  • ax.pie- pie chart
  • ax.fill_between- shaded area between two curves

Styling & Limits

Customize the look of a figure.

python
plt.style.use("seaborn-v0_8-darkgrid")   # built-in style sheetax.set_xlim(0, 10)ax.set_ylim(-1, 1)ax.grid(True, alpha=0.3)ax.axhline(0, color="gray", linestyle="--")plt.rcParams["font.size"] = 12            # global rcParams
Pro Tip

Use fig, ax = plt.subplots() (the object-oriented API) instead of bare pyplot state-machine calls in any script or function that builds more than one figure — it avoids subtle bugs from plotting onto the wrong 'current' axes.

Was this cheat sheet helpful?

Explore Topics

#Matplotlib#MatplotlibCheatSheet#DataScience#Beginner#BasicPlot#Subplots#CommonPlotTypes#StylingLimits#OOP#MachineLearning#APIs#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet