Module 4 · Section 9 of 10
Lesson 4.8 - Interactive Charts with Plotly
Target: ~9 min read - 20 min hands-on
Overview
plotly.express builds interactive charts - hover tooltips, zoom, pan - with a syntax
almost as concise as matplotlib. Interactivity matters most when presenting to someone
who wants to explore the data. We'll build an interactive field drive-test track:
signal strength measured along a route.
Why This Matters (Engineering Context)
Whether it's a telecom drive test, a mobile air-quality survey, an asset-inspection route, or a delivery run, an interactive track lets a client hover over each point to see the measured value - far more useful in a live presentation than a static path.
Code-Along
import plotly.express as px # concise API for INTERACTIVE charts (hover / zoom / pan)
np.random.seed(31)
n_points = 15
route_time = pd.date_range("2026-04-10 08:00", periods=n_points, freq="3min")
# a route drifting NE, with small random wander added to each coordinate
lat = np.linspace(14.55, 14.70, n_points) + np.random.normal(0, 0.004, n_points)
lon = np.linspace(121.00, 121.10, n_points) + np.random.normal(0, 0.004, n_points)
# cumsum of small steps = a slowly wandering signal; np.clip keeps it in a plausible band
rssi_dbm = np.clip(-70 + np.cumsum(np.random.normal(0, 3, n_points)), -110, -55)
drive_test = pd.DataFrame({"time": route_time, "lat": lat, "lon": lon,
"rssi_dbm": np.round(rssi_dbm, 1)})
# px.line_geo draws lat/lon on a map. hover_name / hover_data set the tooltip contents.
fig = px.line_geo(
drive_test, lat="lat", lon="lon", hover_name="time",
hover_data={"rssi_dbm": True, "lat": ":.3f", "lon": ":.3f"},
title="Field Drive Test - Signal Strength Along Route (hover for RSSI)",
)
# update_traces tweaks the drawn series; here colour the markers by RSSI
fig.update_traces(mode="lines+markers",
marker=dict(size=9, color=drive_test["rssi_dbm"],
colorscale="RdYlGn", showscale=True))
# update_geos frames the map: region, centre, zoom (projection_scale), country borders
fig.update_geos(scope="asia", center=dict(lat=14.62, lon=121.05),
projection_scale=45, showcountries=True)
fig.show()
print(drive_test)
Run it: an interactive map renders showing the route, colored by signal strength (RSSI), with hover tooltips showing the exact time, latitude, longitude, and RSSI at each point. In the notebook you can pan and zoom directly on the chart.
Practice Exercises
- Add a
qualitycolumn classifying each point as"Good"(RSSI >= -85) or"Weak"(< -85), and color the track by category instead of by continuous RSSI. - Build a second interactive chart with
px.scatter()(not geographic) plottingrssi_dbmovertime, with lat/lon on hover. - Export the figure to a standalone HTML file with
fig.write_html("drive_test.html")- why is that useful for sharing with a non-technical stakeholder?
# Try the practice exercises here
Knowledge Check
- What does
plotly.expressadd over static matplotlib charts? - Name one field where an interactive measured-value-along-a-route chart is useful.
- What's one advantage of exporting a Plotly chart to standalone HTML?
Answer key
- Interactivity - hover tooltips, zoom, pan - without much more code
- Telecom drive testing, mobile environmental surveys, asset-inspection routes, delivery/logistics
- It opens in any browser, with no Python installation on the recipient's end
42 / 63 sections · Course home · Join the coaching cohort