Page 1: Foundations & Architecture
What is Matplotlib, and what are its key features?
Matplotlib is a cross-platform, 2D plotting library for Python used to create static,
animated, and interactive visualizations. Its key features include:
o Versatility: Supports line plots, scatter plots, bar charts, histograms, and more.
o Customization: Full control over colors, labels, legends, and annotations.
o Integration: Seamlessly works with NumPy arrays and Pandas DataFrames.
Explain the "Anatomy of a Figure" in Matplotlib.
A plot is composed of several hierarchical objects:
o Figure: The top-level container/canvas that holds everything.
o Axes: The actual area where data is plotted (a Figure can have multiple Axes).
o Axis: The number-line-like objects (X and Y) that define limits and ticks.
o Artist: Everything visible on the figure (lines, text, shapes) is an Artist.
What is the difference between pyplot and pylab ?
pyplot is a module providing a MATLAB-like interface for simple plotting. pylab is a
bulk-import module that combines pyplot and numpy into a single namespace; its
use is now generally discouraged in favour of explicit imports.
Page 2: Basic Plotting & Customization
How do you create basic charts in Matplotlib?
o Line Plot: [Link](x, y) connects data points with lines.
o Scatter Plot: [Link](x, y) shows individual points without connecting them.
o Bar Chart: [Link](x, height) for vertical bars; [Link]() for horizontal bars.
o Histogram: [Link](data, bins=10) to show frequency distributions.
How can you customize the appearance of a plot?
Use specific functions to add context and style:
o Labels: [Link]("X Label") and [Link]("Y Label") .
o Title: [Link]("Plot Title") .
o Grid: [Link](True) adds gridlines for better readability.
o Limits: [Link](min, max) and [Link](min, max) set axis ranges.
What is the role of [Link]() ?
It adds a legend to identify different data series. Use the label parameter in plotting
functions (e.g., [Link](x, y, label="Sales") ) for the legend to pick up the
names.
Page 3: Multi-plots and Subplots
Explain the difference between [Link]() and [Link]() .
o [Link](rows, cols, index) : Adds a single subplot at a specific grid position.
o [Link](rows, cols) : A more modern "Object-Oriented" approach that
returns a Figure and an array of Axes simultaneously.
How do you handle overlapping labels in subplots?
Use plt.tight_layout() . This function automatically adjusts subplot parameters so
that titles and labels don't overlap or get cut off by the figure edge.
How can you plot multiple lines in a single graph?
Simply call [Link]() multiple times before calling [Link]() .
python
[Link](x, y1, label='Line A')
[Link](x, y2, label='Line B')
[Link]()
Use code with caution.
Page 4: Advanced Visualizations & Exporting
How do you create a 3D plot?
Requires the mplot3d toolkit. Use projection='3d' when adding an axes.
python
from mpl_toolkits import mplot3d
ax = [Link](projection='3d')
ax.plot3D(x, y, z)
Use code with caution.
Explain "Annotations" in Matplotlib.
Annotations add descriptive text with arrows to point at specific data features.
Use [Link]('Text', xy=(x,y), xytext=(x2,y2),
arrowprops=dict(...)) .
Difference between [Link]() and [Link]() .
[Link]() opens an interactive window to view the
plot. [Link]('[Link]') saves the current figure directly to a file (PNG,
PDF, SVG) without displaying it.
Page 5: Comparison & Specialized Plots
Matplotlib vs. Seaborn: Which is better?
Seaborn is built on top of Matplotlib.
o Matplotlib: Better for low-level, highly customized, or simple plots.
o Seaborn: Better for statistical visualizations (heatmaps, violin plots) with less code
and better default aesthetics.
What are Specialized Plots like Violin and Box plots?
o Box Plot ( [Link]() ): Shows quartiles, median, and outliers.
o Violin Plot ( [Link]() ): Similar to box plots but also shows the probability
density of the data.
How do you handle images in Matplotlib?
Use [Link] to read files and [Link]() to display them. This is
common in computer vision tasks.