← Back to Python

All Topics

Advertisement

Learn/Python/Data Science

Matplotlib Customization

Topic: Visualization

Advertisement

Introduction

Matplotlib offers extensive customization options for creating publication-quality figures.

Styling

# Line styles
plt.plot(x, y, linestyle="--", linewidth=2, color="red")

# Markers
plt.plot(x, y, marker="o", markersize=5)

# Combined
plt.plot(x, y, "b-", label="Line 1")
plt.plot(x2, y2, "ro", label="Points")

# Grid
plt.grid(True, linestyle="--", alpha=0.7)

Labels and Legends

plt.xlabel("X Label", fontsize=12, fontweight="bold")
plt.ylabel("Y Label", fontsize=12)
plt.title("Title", fontsize=14, pad=20)
plt.legend(loc="upper right")
plt.tick_params(axis="both", labelsize=10)

Saving Figures

plt.savefig("plot.png", dpi=300, bbox_inches="tight")
plt.savefig("plot.pdf")  # Vector format
plt.savefig("plot.svg")  # SVG format

Themes

plt.style.use("seaborn-v0_8-darkgrid")
plt.style.use("ggplot")
plt.style.use("default")

Practice Problems

  1. Create multi-line chart with legend
  2. Add annotations to key points
  3. Customize axis limits and ticks
  4. Save figure in different formats
  5. Apply different style themes

Advertisement

Advertisement

Need More Practice?

Get personalized Python help from ChatWhole's AI-powered platform.

Get Expert Help →