A rainfall tooltip text and month-name ticks
Fill in the blanks · Medium · §10.1 Twelve months of data and graph_objects
This line chart draws the monthly rainfall (mm) at two weather stations, Hill and Bay, from May to October with go.Scatter traces. Make the tooltip show the rainfall at the point (the placeholder %{y} with no format) followed by a space and the unit, as in 310 mm. Write the x-axis date ticks as three-letter English month names, such as May and Jun, and set the y-axis range to [0, 400].
Fill in the three blanks with arguments and a method name. Grading changes the rainfall and draws the chart again.
Code with blanks
import pandas as pd
import plotly.graph_objects as go
dates = pd.date_range("2026-05-01", periods=6, freq="MS")
rain = pd.DataFrame({
"date": list(dates) * 2,
"station": ["Hill"] * 6 + ["Bay"] * 6,
"mm": [95, 140, 310, 280, 160, 60, 80, 120, 260, 330, 190, 75],
})
station_colors = {"Hill": "#56B4E9", "Bay": "#E69F00"}
fig = go.Figure()
for station in ["Hill", "Bay"]:
part = rain[rain["station"] == station]
fig.add_trace(go.Scatter(x=part["date"], y=part["mm"], mode="lines+markers", name=station,
line_color=station_colors[station], ____))
fig.update_layout(title="Monthly rainfall at two stations", hovermode="x unified")
fig.update_xaxes(____)
fig.____(range=[0, 400])
fig.show()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.