Matplotlib
Matplotlib is the foundational plotting library in Python. It provides a MATLAB‑like interface to create static, animated, and interactive visualizations. It integrates well with NumPy and Pandas.
Installation
`pip install matplotlib`
Basic Plot
Use `pyplot` module.
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.title("Sine Wave")
plt.grid(True)
plt.show()
Multiple Plots
Use `subplot` or `plt.subplots`.
fig, axes = plt.subplots(2, 2)
axes[0, 0].plot(x, np.sin(x))
axes[0, 1].plot(x, np.cos(x))
axes[1, 0].hist(np.random.randn(1000), bins=30)
plt.show()
Scatter, Bar, Histogram
Common plots for data exploration.
plt.scatter(x, y)
plt.bar(["A", "B", "C"], [3, 7, 5])
plt.hist(data, bins=20)
Customizing
Colors, line styles, markers, legends, etc.
Two Minute Drill
- Matplotlib is the core plotting library.
- `plt.plot()` for line plots, `plt.scatter()` for scatter, `plt.hist()` for histograms.
- Use `plt.subplots()` for multiple plots.
- Customize with labels, titles, legends, colors.
- Integrates with Pandas (DataFrame.plot()).
Need more clarification?
Drop us an email at career@quipoinfotech.com
