Introducing a new way to review your PRs.

Read the announcement

plotly / plotly.py

The interactive graphing library for Python :sparkles:

View on GitHub

13 documents · Updated Nov 16, 2026

overview

Knowledge Base updated: 2026-11-16

Knowledge Base Index

Orientation

plotly.py is the Python interface for building Plotly figures: users create schema-backed figures through plotly.graph_objects, higher-level helpers such as Plotly Express and figure factories, then serialize, render, export, or display them through plotly.io and offline/Jupyter integrations.

Main parts:

  • plotly.graph_objs / plotly.graph_objects — generated schema-backed figure, trace, layout, and frame classes.
  • _plotly_utils and plotly.validators — validation, coercion, lazy imports, and shared utility behavior.
  • plotly.express — high-level chart functions that normalize user data and build figures.
  • plotly.io and plotly.offline — JSON/HTML rendering, static image export, renderer selection, and notebook/file display.
  • codegen and templategen — build-time generation for graph object classes, validators, and built-in templates.
  • js and plotly/labextension — Jupyter widget frontend integration.

Critical state is file-based and bundled with the package rather than stored in a service database:

Architecture diagrams

flowchart TD
  User[User code] --> GO[plotly.graph_objects / graph_objs]
  User --> PX[plotly.express]
  User --> FF[plotly.figure_factory]
  User --> Offline[plotly.offline]

  PX --> GO
  FF --> GO
  Offline --> IO[plotly.io]
  GO --> Validators[plotly.validators + _plotly_utils.basevalidators]
  GO --> IO

  IO --> PackageData[plotly/package_data]
  IO --> Kaleido[Kaleido image export]
  IO --> Browser[HTML / browser / notebook renderers]

  subgraph Build-time generation
    Schema[codegen/resources/plot-schema.json] --> Codegen[codegen]
    Codegen --> GO
    Codegen --> Validators
    Templategen[templategen] --> PackageData
  end

  subgraph Jupyter frontend
    GO --> Widgets[basewidget / FigureWidget]
    Widgets --> JS[js package]
    JS --> Lab[plotly/labextension]
    Lab --> PackageData
  end
flowchart LR
  ChartCall[px.scatter / px.line / etc.] --> Args[Express argument processing]
  Args --> Data[DataFrame / array / special input normalization]
  Data --> Mapping[Trace, facet, color, animation mapping]
  Mapping --> Figure[graph_objects Figure]
  Figure --> Validate[Validator coercion]
  Figure --> Render[plotly.io / offline display]
flowchart LR
  Schema[plot-schema.json] --> Codegen[codegen commands]
  Codegen --> Datatypes[plotly/graph_objs generated classes]
  Codegen --> FigureClasses[Figure / FigureWidget classes]
  Codegen --> ValidatorJSON[plotly/validators/_validators.json]
  ValidatorJSON --> Cache[plotly.validator_cache]
  Cache --> Runtime[Runtime graph object validation]
sequenceDiagram
  participant User
  participant Figure as Graph object figure
  participant IO as plotly.io
  participant Assets as plotly/package_data
  participant Target as Browser/Notebook/File/Kaleido

  User->>Figure: build or mutate figure
  Figure->>Figure: validate and coerce properties
  User->>IO: show/write_html/to_json/write_image
  IO->>Assets: load templates, Plotly.js, bundle data
  IO->>Target: render HTML, JSON, or static image

Glossary

  • Graph object — a schema-backed Python object representing a Plotly figure, trace, layout, frame, or nested property.
  • Plotly Express — the high-level plotly.express chart API that turns tabular inputs and semantic mappings into graph-object figures.
  • Figure factory — legacy helpers under plotly.figure_factory that construct specialized figures from domain-specific inputs.
  • Kaleido — the static image export backend used by plotly.io for image generation.
  • matplotlylib — the Matplotlib-to-Plotly conversion bridge under plotly/matplotlylib.

Codebase-wide invariants

  • Generated graph object classes live primarily under plotly/graph_objs/**, while plotly/graph_objects/ is a small public import surface; route graph-object API changes through the graph object data model doc.
  • Bundled runtime assets are packaged under plotly/package_data/**, including plotly.min.js, widgetbundle.js, datasets/, and templates/.
  • Validation has both generated metadata and shared validator machinery: generated validator metadata is in plotly/…/_validators.json, while reusable validator classes are in _plotly_utils/basevalidators.py.
  • Tests are partitioned by subsystem under tests/test_core/**, tests/test_io/**, tests/test_optional/**, and tests/test_plotly_utils/**; route test-only changes using the same subsystem paths in the table below.

Routing table