9.
1 A Brief matplotlib API Primer
What is Matplotlib?
Matplotlib is a Python library used for data visualization
It helps create line plots, bar charts, histograms, scatter plots, etc.
Commonly used with NumPy and Pandas
Figure 9-1. Simple line plot
2. Figures and Subplots
Figure 9-2. An empty matplotlib figure with three subplots
[Link]
Figure 9-3. Data visualization after a single plot
3. Adjusting the spacing around subplots
Figure 9-5. Data visualization with no inter-subplot spacing
4. Colors, Markers, and Line Styles
Figure 9-6. Line plot with markers
What it shows
color='red' → line color
linestyle='--' → dashed line
marker='o' → circle markers
5. Ticks, Labels, and Legends
1. Ticks
Ticks are the small marks on X-axis and Y-axis that show scale values.
They help us understand where data points lie on the graph.
By default, Matplotlib sets ticks automatically, but we can customize them.
2. Labels
Labels describe what the axes and the graph represent.
They include:
xlabel → name of X-axis
ylabel → name of Y-axis
title → heading of the graph
3. Legends
A legend identifies different lines or data sets in a graph.
It is useful when multiple plots are drawn on the same figure.
Fig: Simple plot with default ticks
Fig: Plot with custom ticks and labels
Fig: Plot with three lines and legend