← Back to Python

All Topics

Advertisement

Learn/Python/Data Science

Matplotlib Advanced Plots

Topic: Visualization

Advertisement

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

  1. Create 3D surface plot
  2. Draw contour plot with labels
  3. Build dashboard with subplots
  4. Add colorbars to plots
  5. Customize 3D plot angles

Advertisement

Advertisement

Need More Practice?

Get personalized Python help from ChatWhole's AI-powered platform.

Get Expert Help →