Plotly is a Python-friendly library for creating visually appealing, interactive charts through an intuitive API. It fits naturally into Streamlit applications, making queried data easier to explore and communicate. section 9.1.4 section 9.3
A practical Plotly workflow can:
- Prepare and order data with DuckDB, then fetch it into a DataFrame. section 9.1.4
- Construct a scatterplot with plotly.express, mapping columns to axes, color, point size, and category order. section 9.1.4
- Render the resulting figure in Streamlit and extend it with vertical year markers. section 9.1.4
Tennis-match timeline
Create a scatterplot of Murray and Nadal matches, placing tournament dates on the x-axis, tournament names on the y-axis, winner names in color, and round importance in point size. Add a vertical line for each year to make the timeline easier to read. section 9.1.4
fig = px.scatter(sorted_matches_for_players,
x="tourney_date",
y="tourney_name",
color="winner_name",
size="roundOrder",
color_discrete_sequence=px.colors.qualitative.Plotly, #1
category_orders={
"tourney_name": ( #2
sorted_matches_for_players['tourney_name']
.drop_duplicates()
.tolist()
)
},
)
Inspect the concise plotly.express construction pattern for a multi-encoding scatterplot. section 9.1.4

