0
0
Matplotlibdata~30 mins

Overlaying data on images in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Overlaying Data on Images
📖 Scenario: You have a photo of a city map. You want to show some important locations on this map by drawing colored dots on top of the image. This helps people see where the places are directly on the map.
🎯 Goal: Learn how to load an image using matplotlib and overlay colored dots on specific coordinates on the image.
📋 What You'll Learn
Use matplotlib.pyplot to load and show an image
Create a list of coordinates for points to overlay
Plot colored dots on the image at the given coordinates
Display the final image with the dots visible
💡 Why This Matters
🌍 Real World
Overlaying data points on images is useful in maps, medical images, and satellite photos to highlight important locations or features.
💼 Career
Data scientists often need to visualize data on images to communicate insights clearly, such as marking hotspots on a map or anomalies in scans.
Progress0 / 4 steps
1
Load the city map image
Import matplotlib.pyplot as plt and load the image file named 'city_map.png' into a variable called img using plt.imread.
Matplotlib
Need a hint?

Use plt.imread('city_map.png') to read the image file.

2
Create a list of location coordinates
Create a list called locations with these exact tuples representing points on the map: (100, 150), (200, 300), and (350, 400).
Matplotlib
Need a hint?

Use square brackets to create the list and tuples inside parentheses.

3
Plot the image and overlay the points
Use plt.imshow(img) to show the image. Then use a for loop with variables x and y to iterate over locations. Inside the loop, plot a red dot at each (x, y) coordinate using plt.scatter(x, y, color='red').
Matplotlib
Need a hint?

Remember to call plt.imshow(img) before plotting the dots.

4
Display the final image with overlays
Add a line to display the plot using plt.show().
Matplotlib
Need a hint?

Use plt.show() to display the image with the dots.