Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Map Local News Events | Data Analysis and Visualization for Media
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Journalists and Media

bookChallenge: Map Local News Events

Mapping local news events is a powerful way to tell stories visually, allowing audiences to quickly grasp the scope, distribution, and types of incidents occurring in their communities. By placing events on a map according to their geographic coordinates, you can reveal patterns and clusters that might otherwise go unnoticed in raw data tables. This approach is especially valuable for journalists aiming to contextualize news, highlight hotspots, or draw attention to trends across neighborhoods or regions.

12345678910111213141516171819202122232425262728
import pandas as pd import matplotlib.pyplot as plt # Sample DataFrame of local news events data = { "event": ["Burglary", "Town Hall", "Charity Run", "Robbery", "Election Rally", "Food Drive"], "type": ["crime", "politics", "community", "crime", "politics", "community"], "latitude": [40.7128, 40.7135, 40.7150, 40.7142, 40.7130, 40.7160], "longitude": [-74.0060, -74.0050, -74.0070, -74.0045, -74.0080, -74.0030] } df = pd.DataFrame(data) # Assign a color to each event type color_map = {"crime": "red", "politics": "blue", "community": "green"} df["color"] = df["type"].map(color_map) # Plotting the events plt.figure(figsize=(8, 6)) for event_type in df["type"].unique(): subset = df[df["type"] == event_type] plt.scatter(subset["longitude"], subset["latitude"], c=subset["color"], label=event_type.capitalize(), s=100, edgecolor="black") plt.title("Local News Events Map") plt.xlabel("Longitude") plt.ylabel("Latitude") plt.legend(title="Event Type") plt.show()
copy

Using color-coding for different event types makes the map much easier to interpret at a glance. When each category—such as crime, politics, or community—is assigned a distinct color, you can quickly identify clusters, outliers, or locations where certain types of events are more common. This not only improves the visual appeal of your map but also helps your audience draw meaningful conclusions from the data.

Taak

Swipe to start coding

Write a function that takes a DataFrame of local news events and produces a scatter plot map.

  • Plot each event as a point using its longitude and latitude.
  • Assign a unique color to each event type category.
  • Include a legend that explains the color for each event type.
  • Add a title to the map.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 7
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you explain how to add more event types and colors to the map?

How can I use real-world data instead of the sample data provided?

What are some best practices for interpreting patterns on these maps?

close

bookChallenge: Map Local News Events

Veeg om het menu te tonen

Mapping local news events is a powerful way to tell stories visually, allowing audiences to quickly grasp the scope, distribution, and types of incidents occurring in their communities. By placing events on a map according to their geographic coordinates, you can reveal patterns and clusters that might otherwise go unnoticed in raw data tables. This approach is especially valuable for journalists aiming to contextualize news, highlight hotspots, or draw attention to trends across neighborhoods or regions.

12345678910111213141516171819202122232425262728
import pandas as pd import matplotlib.pyplot as plt # Sample DataFrame of local news events data = { "event": ["Burglary", "Town Hall", "Charity Run", "Robbery", "Election Rally", "Food Drive"], "type": ["crime", "politics", "community", "crime", "politics", "community"], "latitude": [40.7128, 40.7135, 40.7150, 40.7142, 40.7130, 40.7160], "longitude": [-74.0060, -74.0050, -74.0070, -74.0045, -74.0080, -74.0030] } df = pd.DataFrame(data) # Assign a color to each event type color_map = {"crime": "red", "politics": "blue", "community": "green"} df["color"] = df["type"].map(color_map) # Plotting the events plt.figure(figsize=(8, 6)) for event_type in df["type"].unique(): subset = df[df["type"] == event_type] plt.scatter(subset["longitude"], subset["latitude"], c=subset["color"], label=event_type.capitalize(), s=100, edgecolor="black") plt.title("Local News Events Map") plt.xlabel("Longitude") plt.ylabel("Latitude") plt.legend(title="Event Type") plt.show()
copy

Using color-coding for different event types makes the map much easier to interpret at a glance. When each category—such as crime, politics, or community—is assigned a distinct color, you can quickly identify clusters, outliers, or locations where certain types of events are more common. This not only improves the visual appeal of your map but also helps your audience draw meaningful conclusions from the data.

Taak

Swipe to start coding

Write a function that takes a DataFrame of local news events and produces a scatter plot map.

  • Plot each event as a point using its longitude and latitude.
  • Assign a unique color to each event type category.
  • Include a legend that explains the color for each event type.
  • Add a title to the map.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 7
single

single

some-alt