Matplotlib Basics
Create line charts, bar charts and scatter plots with Python's core plotting library
Matplotlib is the foundation of Python visualisation. Every other visualisation library (Seaborn, Pandas plot, Plotly) is built on top of it. For data analysts, Matplotlib is used to quickly visualise data while exploring it and to create clean charts for reports.
You will use two styles: the plt shortcut style (quick, for notebooks) and the Figure/Axes style (for multiple charts and fine control). Learn both — the plt style for exploration, Figure/Axes for publication-ready charts.
Example
Key Points
- ✓import matplotlib.pyplot as plt — universal convention
- ✓plt.figure(figsize=(width, height)) — always set size before plotting
- ✓plt.savefig("name.png", dpi=150, bbox_inches="tight") saves to file
- ✓plt.tight_layout() prevents title/label overlap — call before show() or savefig()
- ✓Pandas has built-in plot: df["Sales"].plot(kind="bar") wraps Matplotlib automatically
Practice Question
Which parameter controls the size of a Matplotlib figure?
Related Topics
Seaborn for Statistical ChartsCreate beautiful distribution, correlation and categorical charts with SeabornExploratory Data Analysis (EDA) WorkflowA systematic 6-step EDA process every data analyst should follow on any new datasetCapstone Project — Sales AnalysisEnd-to-end data analysis project: load, clean, analyse and visualise sales data