Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære 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.

Oppgave

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.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 7
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

bookChallenge: Map Local News Events

Sveip for å vise menyen

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.

Oppgave

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.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 7
single

single

some-alt