Plotly integration patterns
Let's look at common Plotly patterns the Visualization Agent generates. Understanding these helps you customize and debug visualizations.
Plotly chart types
Choosing the right chart type for your data
bar_chart_example.py
python
import plotly.express as px
# Bar chart for category comparisons
fig = px.bar(
df.head(10),
x='product_category_name_english',
y='total_sales',
title='Top 10 Product Categories by Sales',
color='total_sales',
color_continuous_scale='Viridis'
)
fig.update_layout(
xaxis_title="Category",
yaxis_title="Total Sales ($)",
xaxis_tickangle=-45
)A typical bar chart pattern for category comparisons.
Bar charts work well for category comparisons. For time series data, a line chart is a better fit. Here is the pattern for time-based visualizations.
line_chart_example.py
python
import plotly.express as px
# Line chart for time series
fig = px.line(
df,
x='order_date',
y='order_count',
title='Orders Over Time',
markers=True
)
fig.update_layout(
xaxis_title="Date",
yaxis_title="Number of Orders",
hovermode="x unified"
)A time series line chart pattern.
Quiz: Quiz
Loading practice…
Flashcards: Flashcards
Loading practice…
Checkpoint: Plotly knowledge check
Loading practice…
You now know both Plotly APIs and how to serialize charts for the web. The visualization pipeline is complete.
Validation checklist: Visualization checklist
Loading practice…