Awesome-Agent-Skills-for-Empirical-Research plotly
git clone https://github.com/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research
T=$(mktemp -d) && git clone --depth=1 https://github.com/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/17-DAAF-Contribution-Community-daaf/dot-claude/skills/plotly" ~/.claude/skills/brycewang-stanford-awesome-agent-skills-for-empirical-research-plotly && rm -rf "$T"
skills/17-DAAF-Contribution-Community-daaf/dot-claude/skills/plotly/SKILL.mdPlotly Skill
Plotly interactive visualization library for Python. Covers Plotly Express and Graph Objects for scatter, line, bar, histogram, box, heatmap, 3D, and geographic charts; subplots and faceting; styling; and HTML/image export. Use when creating interactive visualizations with hover/zoom/pan, building web-based charts, or producing geographic or 3D plots. Prefer over plotnine when interactivity is required; for spatial analysis, projections, or GIS-style mapping, use geopandas.
Quick reference for creating interactive data visualizations with Plotly, featuring both the high-level Plotly Express API and low-level Graph Objects.
What is Plotly?
Plotly is an interactive visualization library for Python:
- Interactive: Hover, zoom, pan, and select built-in
- Two APIs: Plotly Express (simple) and Graph Objects (flexible)
- Web-based: Renders as HTML/JavaScript, works in notebooks and browsers
- Wide chart support: 40+ chart types including statistical, scientific, financial, and geographic
How to Use This Skill
Reference File Structure
| File | Purpose | When to Read |
|---|---|---|
| Installation, imports, px vs go | Starting out |
| Scatter, line, bar, histogram, box | Creating visualizations |
| Multi-panel layouts, faceting | Multiple charts together |
| Templates, colors, layout | Customizing appearance |
| HTML, images, JSON | Saving and sharing |
| Common errors, best practices | Debugging |
Quick Decision Trees
"I need to create a chart"
What kind of chart? ├─ Scatter plot → ./references/charts.md ├─ Line chart → ./references/charts.md ├─ Bar chart → ./references/charts.md ├─ Histogram → ./references/charts.md ├─ Box/Violin plot → ./references/charts.md ├─ Heatmap → ./references/charts.md ├─ 3D/Maps/Financial → ./references/charts.md (Other Chart Types) └─ Not sure → ./references/quickstart.md
"I need multiple charts"
Multiple panels? ├─ Same chart, split by category → ./references/subplots-facets.md (faceting) ├─ Different charts in grid → ./references/subplots-facets.md (make_subplots) ├─ Shared axes → ./references/subplots-facets.md └─ Secondary y-axis → ./references/subplots-facets.md
"I need to customize appearance"
What to customize? ├─ Overall theme → ./references/styling.md (templates) ├─ Colors → ./references/styling.md ├─ Titles/labels → ./references/styling.md ├─ Axes → ./references/styling.md ├─ Legend → ./references/styling.md └─ Hover info → ./references/styling.md
"I need to save/export"
Export format? ├─ Interactive HTML → ./references/export.md ├─ Static image (PNG/SVG/PDF) → ./references/export.md ├─ JSON for API → ./references/export.md └─ Embed in webpage → ./references/export.md
"Something isn't working"
Common issues? ├─ Figure not showing → ./references/gotchas.md ├─ Image export fails → ./references/gotchas.md ├─ Performance issues → ./references/gotchas.md ├─ px vs go confusion → ./references/gotchas.md └─ Column/data errors → ./references/gotchas.md
File-First Execution in Research Workflows
Important: In data research pipelines (see
CLAUDE.md), all visualizations are generated through script files in scripts/stage8_analysis/, not interactively. This ensures auditability and reproducibility.
The pattern:
- Write plot code FIRST to
scripts/stage8_analysis/{step}_{plot-name}.py - Execute via Bash with automatic output capture wrapper script
- Validation results get automatically embedded in scripts as comments
- If failed, create versioned copy for fixes
Closely read
agent_reference/SCRIPT_EXECUTION_REFERENCE.md for the mandatory file-first execution protocol covering complete code file writing, output capture, and file versioning rules.
See:
— Stage 8 (Analysis & Visualization)agent_reference/WORKFLOW_PHASE4_ANALYSIS.md
The examples below show Plotly syntax. In research workflows, wrap them in scripts following the file-first pattern.
Quick Reference
Essential Imports
import plotly.express as px # High-level API import plotly.graph_objects as go # Low-level API from plotly.subplots import make_subplots # For subplots import plotly.io as pio # For export/config
Plotly Express Pattern
import plotly.express as px fig = px.scatter(df, x="col_x", y="col_y", color="category") fig.show()
Graph Objects Pattern
import plotly.graph_objects as go fig = go.Figure() fig.add_trace(go.Scatter(x=x_data, y=y_data, mode="markers")) fig.update_layout(title="My Plot") fig.show()
Common px Functions
| Function | Chart Type |
|---|---|
| Scatter plot |
| Line chart |
| Bar chart |
| Histogram |
| Box plot |
| Violin plot |
| Heatmap/Image |
| Pie chart |
Common go Trace Types
| Trace | Use Case |
|---|---|
| Points, lines, or both |
| Bar charts |
| Histograms |
| Box plots |
| Heatmaps |
| Pie charts |
Saving Plots
# Interactive HTML fig.write_html("plot.html") # Static image export (PNG/SVG/PDF) is NOT available in DAAF — kaleido is not # installed due to its heavy Chromium dependency. Use plotnine for static figures. # For interactive output, use HTML: # fig.write_image("plot.png") # Would require: pip install kaleido + Chromium
Topic Index
| Topic | Reference File |
|---|---|
| Installation | |
| px vs go | |
| Built-in datasets | |
| Scatter plots | |
| Line charts | |
| Bar charts | |
| Histograms | |
| Box plots | |
| Other chart types | |
| Faceting | |
| make_subplots | |
| Templates/Themes | |
| Colors | |
| Layout customization | |
| Hover customization | |
| HTML export | |
| Image export | |
| JSON export | |
| Common errors | |
| Performance | |
| Best practices | |
Citation
When this library is used as a primary analytical tool, include in the report's Software & Tools references:
Plotly Technologies Inc. Plotly: Interactive graphing library [Computer software]. https://plotly.com/
Cite when: Plotly is the primary visualization library producing interactive figures included in the report or notebook. Do not cite when: Only used for quick exploratory plots not included in deliverables.