1/16
By the end of this section, students should be able to... • Generate basic line plots using matplotlib.pyplot • Label plots with axes, titles, and legends • Customize plots (colors, styles, markers) • Create multiple plots (subplots or overlayed) • Save plots to image files • Understand the difference between MATLAB-style and object-oriented usage
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Matplotlib
A Python library used to create static, animated, and interactive visualizations.
pyplot
A submodule of matplotlib that mimics MATLAB-style plotting commands.
import matplotlib.pyplot as plt -- Standard import convention to access plotting functions with a shorter alias.
Basic Plot
A visual representation of x vs. y data using plt.plot(x, y)
.
Axes Labeling
Adding context to plots using xlabel()
, ylabel()
, and title()
functions.
Gridlines
Optional lines on the plot background for reference, toggled using plt.grid(True)
or False
.
Legend
A descriptive label for each plotted line; shown using plt.legend()
if label=
was provided in the plot call.
Plot Display
The command plt.show()
renders the plot in a window or output cell.
Customization
Control visual style with arguments like color
, linestyle
, marker
, and linewidth
.Li
Line Styles
Define how lines appear: solid (-
), dashed (--
), dotted (:
), or dash-dot (-.'
).
Markers
Symbols at each data point (e.g., o
for circles, ^
for triangles, s
for squares).
Colors
Use single-letter codes ('r'
for red) or hex codes ('#1f77b4'
) for precise color control.
Axis Limits
Set viewing ranges using plt.axis([xmin, xmax, ymin, ymax])
or separately with xlim()
/ylim()
.
Overlayed Plots
Calling plt.plot()
multiple times adds several lines to the same graph—useful for comparisons.
Subplots
Organize multiple plots in a grid using plt.subplot(n_rows, n_cols, plot_index)
.
tight_layout()
Automatically adjusts spacing to prevent overlapping labels or axes in subplot grids.
MATLAB vs. Python Plotting
Python allows both MATLAB-style procedural plots and object-oriented plotting for complex needs.
Plot Use (in Engineering)
Useful for visualizing functions, simulations, and comparative data analysis.