plotly by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill plotly用于创建交互式、出版质量可视化的 Python 绘图库,支持 40 多种图表类型。
安装 Plotly:
uv pip install plotly
使用 Plotly Express(高级 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()
适用于快速创建具有合理默认设置的标准可视化:
完整指南请参阅 reference/plotly-express.md。
适用于精细控制和自定义可视化:
完整指南请参阅 reference/graph-objects.md。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
注意: Plotly Express 返回的是 graph objects 的 Figure 对象,因此可以结合两种方法使用:
fig = px.scatter(df, x='x', y='y')
fig.update_layout(title='Custom Title') # 在 px 图形上使用 go 方法
fig.add_hline(y=10) # 添加形状
Plotly 支持 40 多种图表类型,按类别组织:
基础图表: 散点图、折线图、条形图、饼图、面积图、气泡图
统计图表: 直方图、箱线图、小提琴图、分布图、误差条
科学图表: 热力图、等高线图、三元图、图像显示
金融图表: K线图、OHLC 图、瀑布图、漏斗图、时间序列图
地图: 散点地图、等值区域图、密度地图(地理可视化)
3D 图表: 3D 散点图、曲面图、网格图、锥形图、体积图
专业图表: 旭日图、树状图、桑基图、平行坐标图、仪表图
所有图表类型的详细示例和用法,请参阅 reference/chart-types.md。
子图: 创建具有共享轴的多图图形:
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)
模板: 应用协调一致的样式:
fig = px.scatter(df, x='x', y='y', template='plotly_dark')
# 内置模板:plotly_white, plotly_dark, ggplot2, seaborn, simple_white
自定义: 控制外观的每个方面:
完整的布局和样式选项,请参阅 reference/layouts-styling.md。
内置交互功能:
可自定义数据的悬停提示框
平移和缩放
图例切换
框选/套索选择
时间序列的范围滑块
按钮和下拉菜单
动画
fig.update_traces( hovertemplate='<b>%{x}</b><br>Value: %{y:.2f}<extra></extra>' )
fig.update_xaxes(rangeslider_visible=True)
fig = px.scatter(df, x='x', y='y', animation_frame='year')
完整的交互性指南,请参阅 reference/export-interactivity.md。
交互式 HTML:
fig.write_html('chart.html') # 完整独立文件
fig.write_html('chart.html', include_plotlyjs='cdn') # 较小文件
静态图像(需要 kaleido):
uv pip install kaleido
fig.write_image('chart.png') # PNG
fig.write_image('chart.pdf') # PDF
fig.write_image('chart.svg') # SVG
完整的导出选项,请参阅 reference/export-interactivity.md。
import plotly.express as px
# 带趋势线的散点图
fig = px.scatter(df, x='temperature', y='yield', trendline='ols')
# 矩阵热力图
fig = px.imshow(correlation_matrix, text_auto=True, color_continuous_scale='RdBu')
# 3D 曲面图
import plotly.graph_objects as go
fig = go.Figure(data=[go.Surface(z=z_data, x=x_data, y=y_data)])
# 分布比较
fig = px.histogram(df, x='values', color='group', marginal='box', nbins=30)
# 显示所有点的箱线图
fig = px.box(df, x='category', y='value', points='all')
# 小提琴图
fig = px.violin(df, x='group', y='measurement', box=True)
# 带范围滑块的时间序列
fig = px.line(df, x='date', y='price')
fig.update_xaxes(rangeslider_visible=True)
# K线图
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']
)])
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)
对于交互式 Web 应用程序,请使用 Dash(Plotly 的 Web 应用框架):
uv pip install dash
import 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_server(debug=True)
每周安装量
312
仓库
GitHub 星标数
23.4K
首次出现
Jan 21, 2026
安全审计
安装于
opencode266
gemini-cli253
codex246
cursor234
github-copilot229
claude-code212
Python graphing library for creating interactive, publication-quality visualizations with 40+ chart types.
Install Plotly:
uv pip install plotly
Basic 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()
For quick, standard visualizations with sensible defaults:
See reference/plotly-express.md for complete guide.
For fine-grained control and custom visualizations:
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 shapes
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.
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_white
Customization: Control every aspect of appearance:
For complete layout and styling options, see reference/layouts-styling.md.
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
fig.update_traces( hovertemplate='<b>%{x}</b><br>Value: %{y:.2f}<extra></extra>' )
fig.update_xaxes(rangeslider_visible=True)
fig = px.scatter(df, x='x', y='y', animation_frame='year')
For complete interactivity guide, see reference/export-interactivity.md.
Interactive HTML:
fig.write_html('chart.html') # Full standalone
fig.write_html('chart.html', include_plotlyjs='cdn') # Smaller file
Static Images (requires kaleido):
uv pip install kaleido
fig.write_image('chart.png') # PNG
fig.write_image('chart.pdf') # PDF
fig.write_image('chart.svg') # SVG
For complete export options, see reference/export-interactivity.md.
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)])
# 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 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']
)])
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)
For interactive web applications, use Dash (Plotly's web app framework):
uv pip install dash
import 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_server(debug=True)
Weekly Installs
312
Repository
GitHub Stars
23.4K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode266
gemini-cli253
codex246
cursor234
github-copilot229
claude-code212
DOCX文件创建、编辑与分析完整指南 - 使用docx-js、Pandoc和Python脚本
43,600 周安装