A scatter plot with the trail name at the top of the tooltip

Write code · Medium · §9.2 Scatter plots, tooltips, and averages

The table trails holds the length (km) and the weekend hikers of six hiking trails. With Plotly Express, draw a scatter plot with the length (length) on the x-axis and the hikers (hikers) on the y-axis, with one color per difficulty level (level).

Show the trail name (trail) in bold at the top of the tooltip, and below it the level, the two axis values, and the climb (climb). Use the dictionary names for the names in the tooltip and on the axes, and make the points size 12. Show the figure with fig.show(). Grading changes the hiker counts and the climbs and draws the chart again.

Target figure for A scatter plot with the trail name at the top of the tooltip
Target figure

Starter code

import pandas as pd
import plotly.express as px

trails = pd.DataFrame({
    "trail": ["Pine", "Ridge", "Valley", "Summit", "Creek", "Rock"],
    "level": ["Easy", "Easy", "Medium", "Medium", "Hard", "Hard"],
    "length": [2.5, 4.0, 5.5, 3.0, 8.0, 6.5],
    "hikers": [320, 260, 180, 210, 90, 120],
    "climb": [150, 220, 400, 350, 900, 700],
})
names = {"length": "Length (km)", "hikers": "Weekend hikers", "climb": "Climb (m)", "level": "Level"}

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