Matplotlib Basics
Matplotlib is Python's primary plotting library. It provides fine-grained control over visualizations.
Basic Plots
Line plots: plt.plot(x, y). Scatter plots: plt.scatter(x, y). Bar charts: plt.bar(x, height). Histograms: plt.hist(data).
Figure and axes control the structure: fig, ax = plt.subplots(). Multiple plots on one figure.
Customization: labels, titles, legends, colors, line styles. The object-oriented interface gives precise control.
Subplots and Layouts
Subplots create multiple plots: fig, axes = plt.subplots(2, 2). Each axes object controls its plot.
GridSpec provides more complex layouts. constrained_layout and tight_layout handle spacing.
Saving and Show
Plots display with plt.show(). Saving: fig.savefig('plot.png', dpi=300). Formats: png, pdf, svg.
Key Takeaways
- Matplotlib provides comprehensive plotting capabilities
- Object-oriented interface offers fine control
- Subplots and layouts enable complex visualizations