Plotly Studio
Powerful skill for interactive, scientific, statistical, data. Includes structured workflows, validation checks, and reusable patterns for scientific.
Plotly Studio
Create interactive, publication-quality visualizations using Plotly's Python library. This skill covers Plotly Express for quick charts, Graph Objects for full customization, subplots, animations, and deploying interactive dashboards.
When to Use This Skill
Choose Plotly Studio when you need to:
- Build interactive charts with hover tooltips, zoom, and pan capabilities
- Create web-ready visualizations that users can explore dynamically
- Generate animated charts showing data changes over time
- Build dashboards with interconnected interactive plots
Consider alternatives when:
- You need static publication figures with precise typographic control (use matplotlib)
- You need statistical visualizations with minimal code (use Seaborn)
- You need real-time streaming data visualizations (use Bokeh with server)
Quick Start
pip install plotly pandas kaleido
import plotly.express as px import pandas as pd # Quick interactive scatter plot df = px.data.gapminder() fig = px.scatter( df.query("year == 2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent", hover_name="country", log_x=True, title="GDP vs Life Expectancy (2007)" ) fig.show() # Save as interactive HTML fig.write_html("scatter.html") # Save as static image fig.write_image("scatter.png", scale=2)
Core Concepts
Plotly Express vs Graph Objects
| Feature | Plotly Express (px) | Graph Objects (go) |
|---|---|---|
| Syntax | One-liner functions | Verbose, explicit |
| Customization | Good defaults, limited control | Full control |
| Data input | DataFrames | Arrays, dicts |
| Best for | Quick exploration | Publication figures |
| Learning curve | Low | Medium-high |
Common Chart Types
import plotly.express as px import plotly.graph_objects as go from plotly.subplots import make_subplots import pandas as pd import numpy as np # Line chart with multiple traces df = px.data.stocks() fig = px.line(df, x="date", y=df.columns[1:], title="Stock Prices Over Time") fig.update_layout(yaxis_title="Price (USD)") fig.show() # Heatmap with Graph Objects data = np.random.randn(10, 10) fig = go.Figure(data=go.Heatmap( z=data, colorscale="RdBu_r", zmid=0 )) fig.update_layout(title="Correlation Matrix") fig.show() # Multi-panel figure fig = make_subplots( rows=2, cols=2, subplot_titles=("Scatter", "Histogram", "Box", "Bar") ) fig.add_trace( go.Scatter(x=np.random.randn(100), y=np.random.randn(100), mode="markers"), row=1, col=1 ) fig.add_trace( go.Histogram(x=np.random.randn(500), nbinsx=30), row=1, col=2 ) fig.add_trace( go.Box(y=[np.random.randn(50) for _ in range(4)]), row=2, col=1 ) fig.add_trace( go.Bar(x=["A", "B", "C", "D"], y=[23, 45, 12, 38]), row=2, col=2 ) fig.update_layout(height=600, showlegend=False, title="Dashboard") fig.show()
Animated Visualizations
import plotly.express as px # Animated scatter plot over time df = px.data.gapminder() fig = px.scatter( df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country", size="pop", color="continent", hover_name="country", log_x=True, size_max=55, range_x=[100, 100000], range_y=[25, 90], title="Gapminder: 50 Years of Global Development" ) fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"] = 500 fig.show()
Configuration
| Parameter | Description | Default |
|---|---|---|
template | Visual theme | "plotly" |
color_discrete_sequence | Color palette for categorical data | Plotly default |
color_continuous_scale | Colormap for continuous data | "Viridis" |
width | Figure width in pixels | 700 |
height | Figure height in pixels | 450 |
renderer | Display backend | "browser" |
Best Practices
-
Start with Plotly Express, customize with
update_*— Build the basic chart withpxfunctions, then refine withfig.update_layout(),fig.update_traces(), andfig.update_xaxes(). This gives you speed of Express with the customization of Graph Objects. -
Use
hover_datato add context without clutter — Instead of adding more visual encodings (colors, sizes), put secondary information in hover tooltips withhover_data=["column1", "column2"]. This keeps the chart clean while making details accessible on demand. -
Export with
kaleidofor static images — Installkaleidoforfig.write_image()support. Usescale=2orscale=3for high-DPI outputs. For vector formats, export as SVG or PDF rather than PNG for publication use. -
Set explicit axis ranges for animations — Animated charts with auto-scaling axes produce jarring jumps between frames. Set
range_xandrange_yto encompass the full data range across all animation frames. -
Use
fig.update_layout(template="plotly_white")for clean presentations — The default template has a gray background. Switch to"plotly_white"or"simple_white"for cleaner figures suitable for reports and presentations.
Common Issues
Figures don't display in Jupyter — Plotly needs a renderer configured for your environment. Run import plotly.io as pio; pio.renderers.default = "notebook" for classic Jupyter, or "colab" for Google Colab. VSCode requires the Jupyter extension with "vscode" renderer.
Static image export fails — fig.write_image() requires the kaleido package. Install with pip install kaleido. If kaleido fails on Linux servers, ensure you have required system libraries or use fig.write_html() and convert to image separately.
Large datasets make interactive charts slow — Plotly renders all data points client-side in the browser. For datasets over 10,000 points, use px.scatter(render_mode="webgl") for GPU-accelerated rendering, or downsample data before plotting. WebGL mode handles millions of points smoothly.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Full-Stack Code Reviewer
Comprehensive code review skill that checks for security vulnerabilities, performance issues, accessibility, and best practices across frontend and backend code.
Test Suite Generator
Generates comprehensive test suites with unit tests, integration tests, and edge cases. Supports Jest, Vitest, Pytest, and Go testing.
Pro Architecture Workspace
Battle-tested skill for architectural, decision, making, framework. Includes structured workflows, validation checks, and reusable patterns for development.