Plotly

作者 davila78da17d671b6f無授權條款32K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Interactive scientific and statistical data visualization library for Python. Use when creating charts, plots, or visualizations including scatter plots, line charts, bar charts, heatmaps, 3D plots, geographic maps, statistical distributions, financial charts, and dashboards. Supports both quick visualizations (Plotly Express) and fine-grained customization (graph objects). Outputs interactive HTML or static images (PNG, PDF, SVG).

僅含說明Data & Analytics
AI 產生的概覽

指導用 Python 的 Plotly 建立互動式圖表,從 Plotly Express 快速繪圖到 graph objects 精細客製。

功能
此技能提供使用 Python Plotly 函式庫建立互動式科學、統計、金融與地理視覺化的說明。內容涵蓋 Plotly Express 與 graph objects 兩種 API 的選擇、圖表類型、子圖、範本、樣式、互動功能,以及匯出為互動式 HTML 或靜態 PNG、PDF、SVG。它也指向圖表類型、版面配置、graph objects、Plotly Express 與匯出/互動等參考檔案,並提到用 Dash 建立網頁儀表板。
適用情境
適用於在 Python 中建立圖表、繪圖或儀表板,包括散佈圖、折線圖、長條圖、熱圖、3D 圖、地圖、分布圖與金融圖表。無論是快速的标准視覺化,或需要精細控制的自訂圖形都合適。
執行需求
需要安裝 plotly 套件的 Python 環境;匯出靜態圖片還需 kaleido,網頁儀表板還需 dash。此技能不含指令碼,只有說明與參考文件。

Plotly

Python graphing library for creating interactive, publication-quality visualizations with 40+ chart types.

Quick Start

Install Plotly:

bash
uv pip install plotly

Basic usage with Plotly Express (high-level API):

python
import plotly.express as pximport 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 [blocked] 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 [blocked] for complete guide.

Note: Plotly Express returns graph objects Figure, so you can combine approaches:

python
fig = px.scatter(df, x='x', y='y')fig.update_layout(title='Custom Title')  # Use go methods on px figurefig.add_hline(y=10)                     # Add shapes

Core 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 [blocked].

2. Layouts and Styling

Subplots: Create multi-plot figures with shared axes:

python
from plotly.subplots import make_subplotsimport 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:

python
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:

  • 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 [blocked].

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
python
# Custom hover templatefig.update_traces(    hovertemplate='<b>%{x}</b><br>Value: %{y:.2f}<extra></extra>')
# Add rangesliderfig.update_xaxes(rangeslider_visible=True)
# Animationsfig = px.scatter(df, x='x', y='y', animation_frame='year')

For complete interactivity guide, see reference/export-interactivity.md [blocked].

4. Export Options

Interactive HTML:

python
fig.write_html('chart.html')                       # Full standalonefig.write_html('chart.html', include_plotlyjs='cdn')  # Smaller file

Static Images (requires kaleido):

bash
uv pip install kaleido
python
fig.write_image('chart.png')   # PNGfig.write_image('chart.pdf')   # PDFfig.write_image('chart.svg')   # SVG

For complete export options, see reference/export-interactivity.md [blocked].

Common Workflows

Scientific Data Visualization

python
import plotly.express as px
# Scatter plot with trendlinefig = px.scatter(df, x='temperature', y='yield', trendline='ols')
# Heatmap from matrixfig = px.imshow(correlation_matrix, text_auto=True, color_continuous_scale='RdBu')
# 3D surface plotimport plotly.graph_objects as gofig = go.Figure(data=[go.Surface(z=z_data, x=x_data, y=y_data)])

Statistical Analysis

python
# Distribution comparisonfig = px.histogram(df, x='values', color='group', marginal='box', nbins=30)
# Box plot with all pointsfig = px.box(df, x='category', y='value', points='all')
# Violin plotfig = px.violin(df, x='group', y='measurement', box=True)

Time Series and Financial

python
# Time series with rangesliderfig = px.line(df, x='date', y='price')fig.update_xaxes(rangeslider_visible=True)
# Candlestick chartimport plotly.graph_objects as gofig = go.Figure(data=[go.Candlestick(    x=df['date'],    open=df['open'],    high=df['high'],    low=df['low'],    close=df['close'])])

Multi-Plot Dashboards

python
from plotly.subplots import make_subplotsimport 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):

bash
uv pip install dash
python
import dashfrom dash import dcc, htmlimport 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)

Reference Files

  • plotly-express.md [blocked] - High-level API for quick visualizations
  • graph-objects.md [blocked] - Low-level API for fine-grained control
  • chart-types.md [blocked] - Complete catalog of 40+ chart types with examples
  • layouts-styling.md [blocked] - Subplots, templates, colors, customization
  • export-interactivity.md [blocked] - Export options and interactive features

Additional Resources

來源與署名

來源:davila7/claude-code-templates位於cli-tool/components/skills/scientific/plotly提交8da17d6

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架