Image colormaps
📖 Scenario: You are working with a grayscale image represented as a 2D array of pixel brightness values. You want to visualize this image using different color styles called colormaps to better understand the details.
🎯 Goal: Create a small 2D array representing a grayscale image, set a colormap name, apply the colormap to the image using matplotlib, and display the colored image.
📋 What You'll Learn
Create a 2D numpy array called
image with the exact values [[0, 50, 100], [150, 200, 255]]Create a variable called
cmap_name and set it to the string 'viridis'Use matplotlib's
imshow function with the cmap parameter set to cmap_name to display the imageUse
plt.colorbar() to show the color scale next to the imageUse
plt.show() to display the final image💡 Why This Matters
🌍 Real World
Scientists and engineers often use colormaps to visualize grayscale images such as medical scans, satellite photos, or heatmaps to better understand patterns and details.
💼 Career
Knowing how to apply colormaps is useful for data scientists and analysts who need to present image data clearly and effectively in reports and dashboards.
Progress0 / 4 steps