SAMANTUS Python for Data Analytics — Complete Training Manual CHEAT SHEET 04
← Back to Course Index

Matplotlib Cheat Sheet


On This Page

Bonus Chapter: Matplotlib Cheat Sheet


Quick reference for the Matplotlib charting syntax covered in Module 15.

CS4.1  Basic Chart Types

ChartSyntax
Lineplt.plot(x, y)
Barplt.bar(x, y)
Horizontal Barplt.barh(x, y)
Pieplt.pie(values, labels=labels)
Histogramplt.hist(data, bins=20)
Scatterplt.scatter(x, y)
Box Plotplt.boxplot(data)

CS4.2  Titles, Labels & Legends

► Basic Formatting
plt.title("My Chart Title")
plt.xlabel("X Axis Label")
plt.ylabel("Y Axis Label")
plt.legend(["Series A", "Series B"])
plt.grid(alpha=0.3)
plt.show()

CS4.3  Styling & Customization

ParameterPurpose
color='orange'Line/bar color
marker='o'Point marker style
linewidth=2Line thickness
linestyle='--'Dashed line style
figsize=(8,5)Figure size (in plt.subplots())
rotation=45Rotate axis tick labels (plt.xticks)

CS4.4  Multiple Plots & Saving

► Subplots & Saving Figures
fig, ax = plt.subplots(figsize=(8,5))
ax.plot(x, y)
ax.set_title("Chart Title")

# Multiple subplots in a grid
fig, axes = plt.subplots(1, 2, figsize=(10,4))
axes[0].plot(x, y)
axes[1].bar(categories, values)

# Save to file
plt.savefig("chart.png", dpi=150, bbox_inches="tight")
ℹ Reminder
Full explanations and worked examples for every chart type are in Module 15 of the main training manual.