Data Science Essentials
Matplotlib
A comprehensive library for creating static, animated, and interactive visualizations in Python.
Interview: Reporting and analysis. Tested on basic plotting mechanics (figure vs axis), custom styling, and layout adjustment.
Matplotlib is Python's primary visualization engine. It provides an object-oriented API for building plots, charts, histograms, and scatter plots.
Figure vs. Axes
To understand Matplotlib, you must separate figures from axes:
- Figure: The master canvas container (the window or file containing all plot elements).
- Axes: The individual plot, grid, or subplot inside the figure. An axes has x-ticks, y-ticks, labels, and title. A figure can contain multiple axes.
Use Cases
Scientific Reporting — Generating line/bar charts for research publications.
EDA (Exploratory Data Analysis) — Plotting distributions and correlations to inspect data properties before ML modeling.
Automated Reports — Creating periodic system health dashboard charts.
Common Mistakes
Using the stateful API incorrectly — Mixing `plt.plot()` with object-oriented `ax.plot()` calls, causing configuration confusion in subplots.
Cluttering memory — Forgetting to call `plt.close(fig)` inside automated server scripts, resulting in server memory exhaustion.
Bad label spacing — Exporting figures where x-labels or titles get cropped off due to missing `bbox_inches="tight"` options.