plotly – skill Dữ liệu & Khoa học cho agent AI
Thư viện trực quan hóa tương tác. Dùng khi cần hover, zoom, pan hoặc biểu đồ nhúng được trên web. Phù hợp nhất cho dashboard, phân tích khám phá và thuyết trình. Với hình ảnh xuất bản tĩnh dùng matplotlib hoặc scientific-visualization.
Cài skill plotly bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/plotly-42fa9.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /plotly – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/plotly-42fa9.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $plotly – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/plotly-42fa9.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /plotly – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/plotly-42fa9.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /plotly – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Plotly
Python graphing library for creating interactive, publication-quality visualizations with 40+ chart types.
When to Use
- You need interactive charts with hover, zoom, pan, or web embedding.
- You are building dashboards, exploratory analysis notebooks, or presentations that benefit from rich interaction.
- You want to choose between Plotly Express and Graph Objects for the same visualization task.
Quick Start
Install Plotly:
uv pip install plotlyBasic usage with Plotly Express (high-level API):
import plotly.express as px
import pandas as pd
df = pd.DataFrame({
'x': [1, 2, 3, 4],
'y': [10, 11, 12, 13]
})
fig = px.scatter(df, x='x', y='y', title='My First Plot')
fig.show()Choosing Between APIs
Use Plotly Express (px)
For quick, standard visualizations with sensible defaults:
- Working with pandas DataFrames
- Creating common chart types (scatter, line, bar, histogram, etc.)
- Need automatic color encoding and legends
- Want minimal code (1-5 lines)
See reference/plotly-express.md for complete guide.
Use Graph Objects (go)
For fine-grained control and custom visualizations:
- Chart types not in Plotly Express (3D mesh, isosurface, complex financial charts)
- Building complex multi-trace figures from scratch
- Need precise control over individual components
- Creating specialized visualizations with custom shapes and annotations
See reference/graph-objects.md for complete guide.
Note: Plotly Express returns graph objects Figure, so you can combine approaches:
fig = px.scatter(df, x='x', y='y')
fig.update_layout(title='Custom Title') # Use go methods on px figure
fig.add_hline(y=10) # Add shapesCore Capabilities
1. Chart Types
Plotly supports 40+ chart types organized into categories:
Basic Charts: scatter, line, bar, pie, area, bubble
Statistical Charts: histogram, box plot, violin, distribution, error bars
Scientific Charts: heatmap, contour, ternary, image display
Financial Charts: candlestick, OHLC, waterfall, funnel, time series
Maps: scatter maps, choropleth, density maps (geographic visualization)
3D Charts: scatter3d, surface, mesh, cone, volume
Specialized: sunburst, treemap, sankey, parallel coordinates, gauge
For detailed examples and usage of all chart types, see reference/chart-types.md.
2. Layouts and Styling
Subplots: Create multi-plot figures with shared axes:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=2, cols=2, subplot_titles=('A', 'B', 'C', 'D'))
fig.add_trace(go.Scatter(x=[1, 2], y=[3, 4]), row=1, col=1)Templates: Apply coordinated styling:
fig = px.scatter(df, x='x', y='y', template='plotly_dark')
# Built-in: plotly_white, plotly_dark, ggplot2, seaborn, simple_whiteCustomization: Control every aspect of appearance:
- Colors (discrete sequences, continuous scales)
- Fonts and text
- Axes (ranges, ticks, grids)
- Legends
- Margins and sizing
- Annotations and shapes
For complete layout and styling options, see reference/layouts-styling.md.
3. Interactivity
Built-in interactive features:
- Hover tooltips with customizable data
- Pan and zoom
- Legend toggling
- Box/lasso selection
- Rangesliders for time series
- Buttons and dropdowns
- Animations
# Custom hover template
fig.update_traces(
hovertemplate='<b>%{x}</b><br>Value: %{y:.2f}<extra></extra>'
)
# Add rangeslider
fig.update_xaxes(rangeslider_visible=True)
# Animations
animation_df = pd.DataFrame({'x': [1, 2], 'y': [10, 11], 'year': [2025, 2026]})
fig = px.scatter(animation_df, x='x', y='y', animation_frame='year')For complete interactivity guide, see reference/export-interactivity.md.
4. Export Options
Interactive HTML:
fig.write_html('chart.html') # Full standalone
fig.write_html('chart.html', include_plotlyjs='cdn') # Smaller fileStatic Images (requires kaleido):
uv pip install kaleidofig.write_image('chart.png') # PNG
fig.write_image('chart.pdf') # PDF
fig.write_image('chart.svg') # SVGFor complete export options, see reference/export-interactivity.md.
Common Workflows
Scientific Data Visualization
import plotly.express as px
# Scatter plot with trendline
fig = px.scatter(df, x='temperature', y='yield', trendline='ols')
# Heatmap from matrix
fig = px.imshow(correlation_matrix, text_auto=True, color_continuous_scale='RdBu')
# 3D surface plot
import plotly.graph_objects as go
fig = go.Figure(data=[go.Surface(z=z_data, x=x_data, y=y_data)])Statistical Analysis
# Distribution comparison
fig = px.histogram(df, x='values', color='group', marginal='box', nbins=30)
# Box plot with all points
fig = px.box(df, x='category', y='value', points='all')
# Violin plot
fig = px.violin(df, x='group', y='measurement', box=True)Time Series and Financial
# Time series with rangeslider
fig = px.line(df, x='date', y='price')
fig.update_xaxes(rangeslider_visible=True)
# Candlestick chart
import plotly.graph_objects as go
fig = go.Figure(data=[go.Candlestick(
x=df['date'],
open=df['open'],
high=df['high'],
low=df['low'],
close=df['close']
)])Multi-Plot Dashboards
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(
rows=2, cols=2,
subplot_titles=('Scatter', 'Bar', 'Histogram', 'Box'),
specs=[[{'type': 'scatter'}, {'type': 'bar'}],
[{'type': 'histogram'}, {'type': 'box'}]]
)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Bar(x=['A', 'B'], y=[1, 2]), row=1, col=2)
fig.add_trace(go.Histogram(x=data), row=2, col=1)
fig.add_trace(go.Box(y=data), row=2, col=2)
fig.update_layout(height=800, showlegend=False)Integration with Dash
For interactive web applications, use Dash (Plotly's web app framework):
uv pip install dashimport dash
from dash import dcc, html
import plotly.express as px
app = dash.Dash(__name__)
fig = px.scatter(df, x='x', y='y')
app.layout = html.Div([
html.H1('Dashboard'),
dcc.Graph(figure=fig)
])
app.run(debug=True) # local development only; disable debug for deploymentReference Files
- plotly-express.md - High-level API for quick visualizations
- graph-objects.md - Low-level API for fine-grained control
- chart-types.md - Complete catalog of 40+ chart types with examples
- layouts-styling.md - Subplots, templates, colors, customization
- export-interactivity.md - Export options and interactive features
Additional Resources
- Official documentation: https://plotly.com/python/
- API reference: https://plotly.com/python-api-reference/
- Community forum: https://community.plotly.com/
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
The reference/*.md guides listed above are upstream references and are not bundled here. Use the official documentation for those dependent details. Exported HTML contains the plotted data (including hover fields); inspect it before sharing. CDN export needs network access, and current Kaleido versions may require an available Chrome installation. [Dash 3 migration](https://dash.plotly.com/dash-3-0-migration).
Skill liên quan
- project-state-governor – Quản lý trạng thái dự án chuẩn, có bằng chứng xác thực, xuyên suốt các phiên làm việc…
- pubmed-database – Truy cập trực tiếp REST API của PubMed. Truy vấn Boolean/MeSH nâng cao, E-utilities API…
- quality-nonconformance – Hướng dẫn vận hành cho kiểm soát chất lượng, điều tra sự không phù hợp, phân tích nguyên…
- quant-analyst – Xây dựng mô hình tài chính, backtest chiến lược giao dịch và phân tích dữ liệu thị…
- radar-satellite-analysis – Diễn giải quan trắc radar thời tiết và vệ tinh bằng cách kiểm tra metadata và hình học…
- radare2 – Điều khiển CLI radare2 để trinh sát nhị phân, disassembly, phân tích, định vị hàm…
- radio-sdr – Nghiên cứu bảo mật RF/SDR có ủy quyền: nhận diện tín hiệu, khảo sát khả thi replay trong…
- rag-implementation – Quy trình triển khai RAG (Retrieval-Augmented Generation), gồm chọn embedding, thiết lập…