A PM2.5 chart with only the Suwon line made thicker

Write code · Medium · §9.3 Figure structure and updates

The line chart fig shows a week of fine dust (PM2.5) levels in three cities. Make every line width 1, and then make only the Suwon (Suwon) line width 4 to emphasize it. Leave the colors as they are.

Change the legend title to City, and set the tooltip mode (hovermode) so that one box shows the values of all three cities on the same day. Show the figure with fig.show(). Grading changes the levels and the order of the cities and draws the chart again.

Target figure for A PM2.5 chart with only the Suwon line made thicker
Target figure

Starter code

import pandas as pd
import plotly.express as px

dust = pd.DataFrame({
    "day": [1, 2, 3, 4, 5, 6, 7] * 3,
    "city": ["Suwon"] * 7 + ["Incheon"] * 7 + ["Daejeon"] * 7,
    "pm25": [18, 25, 41, 36, 22, 15, 19, 21, 30, 38, 33, 26, 20, 17, 14, 19, 28, 30, 18, 12, 16],
})
city_colors = {"Suwon": "#0072B2", "Incheon": "#E69F00", "Daejeon": "#009E73"}
fig = px.line(dust, x="day", y="pm25", color="city", color_discrete_map=city_colors,
              title="Daily PM2.5 in three cities")

# Write your code here

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.