Introduction
Advanced plotting techniques including 3D plots, subplots, and animations.
3D Plotting
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X = np.arange(-5, 5, 0.1)
Y = np.arange(-5, 5, 0.1)
X, Y = np.meshgrid(X, Y)
Z = np.sin(X) * np.cos(Y)
ax.plot_surface(X, Y, Z)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
Contour Plots
fig, ax = plt.subplots()
contour = ax.contour(X, Y, Z, levels=20)
ax.clabel(contour, inline=True)
plt.colorbar(contour)
Multiple Subplots
fig, axes = plt.subplots(2, 2, figsize=(10, 8))
axes[0, 0].plot(x, y1)
axes[0, 1].scatter(x, y2)
axes[1, 0].bar(x, y3)
axes[1, 1].hist(y4)
plt.tight_layout()
Practice Problems
- Create 3D surface plot
- Draw contour plot with labels
- Build dashboard with subplots
- Add colorbars to plots
- Customize 3D plot angles