Monthly mean temperatures in two cities

Write code · Medium · §9.1 From static figures to exploration

The table temps holds the monthly mean temperatures (°C) of Seoul (Seoul) and Jeju (Jeju) from January to June. With Plotly Express, draw a line chart with the month (month) on the x-axis and the temperature (temp) on the y-axis, one line per city.

Use the dictionary names for the names on the axis titles, the legend, and the tooltip, and color the cities as the dictionary city_colors says. Set the x-axis tick spacing to 1 (one tick per month) and the y-axis range to [-5, 30]. Show the figure with fig.show(). Grading changes the temperatures and the order of the cities and draws the chart again.

Target figure for Monthly mean temperatures in two cities
Target figure

Starter code

import pandas as pd
import plotly.express as px

temps = pd.DataFrame({
    "month": [1, 2, 3, 4, 5, 6] * 2,
    "city": ["Seoul"] * 6 + ["Jeju"] * 6,
    "temp": [-2.0, 0.5, 6.0, 12.5, 18.0, 22.5, 6.0, 7.0, 10.0, 14.5, 18.5, 22.0],
})
names = {"month": "Month", "city": "City", "temp": "Temperature (C)"}
city_colors = {"Seoul": "#0072B2", "Jeju": "#E69F00"}

# 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.