Multiple images in subplot grid
📖 Scenario: You are working as a data scientist who needs to display multiple images side by side for easy comparison. This is common when analyzing photos, medical scans, or satellite images.
🎯 Goal: Create a grid of subplots using matplotlib and display four different images in this grid.
📋 What You'll Learn
Create a list called
images containing four 2D numpy arrays representing grayscale images.Create a variable called
fig, axes using plt.subplots(2, 2) to make a 2x2 grid of subplots.Use a
for loop with variables ax and img to iterate over axes.flat and images simultaneously.Inside the loop, display each image on its subplot using
ax.imshow(img, cmap='gray').Turn off axis ticks and labels for each subplot using
ax.axis('off').Finally, use
plt.show() to display the figure.💡 Why This Matters
🌍 Real World
Displaying multiple images side by side helps compare different photos or scans quickly, useful in medical imaging, satellite photo analysis, or quality control.
💼 Career
Data scientists and analysts often need to visualize multiple images together to spot patterns, differences, or anomalies.
Progress0 / 4 steps