AI Hints
Home›Data Science Tutorial›Better Charts and Your Career
Data Science · Lesson 77 of 101

Interactive Charts

Letting people explore.

⏱ 2 min read▶ Video at 2:11:42🎓 Free
Watch this lesson in the Data Science courseWatch on YouTube ↗Full Data Science course

A static chart answers one question. But a manager always has one more. What about just Europe? What was that spike in March? Instead of making ten charts, you can give them one that they can explore.

Interactive Charts
From the video: Interactive Charts
  • A static chart answers one question
  • Managers always have one more
  • One chart they can explore

Interactive in a few lines

Plotly Express makes interactive charts with almost no code. We make a table of monthly revenue by region, then ask for a line chart, with a colour for each region. Then we save it as a web page. Run it. That one file opens in any browser, and works with no server. You can hover for exact values, zoom in, and click on the legend to hide a region. Email it to your manager, and they can explore on their own.

interactive.pypython
import pandas as pd
import plotly.express as px

sales = pd.read_csv("sales.csv", parse_dates=["date"])
m = sales.groupby([pd.Grouper(key="date", freq="ME"), "region"])["revenue"].sum().reset_index()

fig = px.line(m, x="date", y="revenue", color="region", title="Monthly revenue by region")
fig.write_html("revenue.html")
print("Saved", len(m), "points to revenue.html")
Output
Saved 96 points to revenue.html

When to use interaction

Interaction is great for exploring. But it's bad for persuading. If you need people to see one specific thing, don't make them hunt for it. In a presentation, show a static chart, with a clear title. Use interactive ones for dashboards, and for people who want to dig deeper.

Exploringinteractive
Persuadingstatic, clear title
Dashboardsinteractive
Slides and reportsstatic

Summary

Use interaction to explore, and static charts to persuade. Next, a simple idea that makes crowded charts readable.

Key takeaways
  • Plotly makes interaction easy
  • Share as one HTML file
  • Static charts persuade better
Next up: Small Multiples — twelve lines, no spaghetti