Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Module 25

Matplotlib

Draw clear line, bar, scatter, histogram, and pie charts with Matplotlib, arrange them in subplots, and save them as files.

Intermediate8 hours 45 min21 lessons

01

What Is Matplotlib

Meet Matplotlib, the plotting library for Python, and draw a first chart from a list of numbers with pyplot in three short lines.

Intermediate25 min

02

Anatomy of a Figure

Learn the parts of a Matplotlib chart: the figure that holds everything, the axes you draw on, and the title, labels, ticks, and legend.

Intermediate25 min

03

Your First Line Plot

Draw line charts with plot, understand what happens when you pass only one list, and add the title and axis names that make a chart readable.

Intermediate25 min

04

Multiple Lines and a Legend

Draw several lines on one set of axes, label each one, and place a legend so a reader can tell the lines apart without asking.

Intermediate25 min

05

Line Styles and Colours

Control how a line looks with colour, line style, width, and transparency, and learn the short aliases that appear in most Matplotlib code.

Intermediate25 min

06

Markers on a Line

Mark the real measurements on a line with marker, and control their shape, size, fill colour, and edge colour with ms, mfc, and mec.

Intermediate25 min

07

Grid Lines and Fonts

Add grid lines so readers can trace a value back to the axis, and style the title and axis names with a font dictionary.

Intermediate25 min

08

Axis Limits and Ticks

Zoom into part of a chart with xlim and ylim, choose which tick numbers appear with xticks and yticks, and see how limits can mislead.

Intermediate25 min

09

Several Plots in One Figure

Split one figure into a grid with plt.subplot, give each panel its own title, and add one heading over the whole figure with suptitle.

Intermediate25 min

10

Working with Figure and Axes Objects

Use plt.subplots to hold the figure and its axes in variables, and learn the set_ methods that replace the plt shortcuts on a real project.

Intermediate25 min

11

Bar Charts

Compare separate categories with plt.bar, control colour and width, and understand why a bar chart must always start at zero.

Intermediate25 min

12

Horizontal Bar Charts

Use plt.barh when category names are long, set the bar thickness with height, and order the bars so the chart reads from the top down.

Intermediate25 min

13

Stacked Bar Charts

Stack one series on top of another with bottom, build the running total for a third layer, and know when stacking helps or hides.

Intermediate25 min

14

Scatter Plots

Plot one dot per observation with plt.scatter to see whether two measurements move together, and read the association honestly.

Intermediate25 min

15

Colour Maps and Dot Sizes

Add a third and fourth measurement to a scatter plot using the c and s arguments, a colour map, and a colour bar that explains the scale.

Intermediate25 min

16

Histograms

Count how many values fall into each range with plt.hist, and learn why a histogram is a different chart from a bar chart.

Intermediate25 min

17

Choosing Histogram Bins

Set the number of bins or their exact edges, work out the bin width, and see how the choice changes the shape a histogram shows.

Intermediate25 min

18

Histogram Styles

Switch between the bar, step, and stepfilled histogram styles, thin the bars with rwidth, and set the fill and edge colours.

Intermediate25 min

19

Pie Charts

Show how a whole splits into parts with plt.pie, label every slice, print the percentages with autopct, and know when a bar chart reads better.

Intermediate25 min

20

Styling a Pie Chart

Pull one slice out with explode, rotate the pie with startangle, add a shadow or a donut hole, and put the labels in a legend instead.

Intermediate25 min

21

Saving Figures

Save a finished chart with savefig as PNG, SVG, or PDF, set its size and resolution, trim the margins, and close figures you no longer need.

Intermediate25 min