Matplotlib Quick-Start Cheatsheet
1. Line Plot (trends over time)
import [Link] as plt
x = [2000, 2001, 2002, 2003, 2004]
y = [2.01, 2.02, 2.03, 2.04, 2.05]
[Link](x, y, marker="o", linestyle="-", color="blue", label="Births per Woman")
[Link]("Line Plot Example")
[Link]("Year")
[Link]("Value")
[Link]()
[Link]()
2. Bar Chart (comparisons between groups)
x = ["Alice", "Bob", "Charlie"]
y = [85, 90, 78]
[Link](x, y, color="green")
[Link]("Bar Chart Example")
[Link]("Name")
[Link]("Score")
[Link]()
3. Histogram (distribution of data)
import numpy as np
data = [Link](1000) # 1000 random numbers
[Link](data, bins=20, color="purple", edgecolor="black")
[Link]("Histogram Example")
[Link]("Value")
[Link]("Frequency")
[Link]()
4. Box Plot (spread and outliers)
data = [[Link](50, 10, 100),
[Link](60, 15, 100),
[Link](70, 20, 100)]
[Link](data, labels=["Group 1", "Group 2", "Group 3"])
[Link]("Box Plot Example")
[Link]("Values")
[Link]()
5. Scatter Plot (relation between 2 variables)
x = [24, 27, 22, 32, 29]
y = [85, 90, 78, 92, 88]
[Link](x, y, color="red")
[Link]("Scatter Plot Example")
[Link]("Age")
[Link]("Score")
[Link]()
6. Subplots (multiple plots in one figure)
fig, axs = [Link](1, 2, figsize=(10, 4))
# Left plot
axs[0].bar(["A", "B", "C"], [10, 20, 15], color="orange")
axs[0].set_title("Bar Chart")
# Right plot
axs[1].plot([1, 2, 3], [2, 4, 6], marker="o", color="blue")
axs[1].set_title("Line Plot")
plt.tight_layout()
[Link]()