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_utilsandplotly.validators— validation, coercion, lazy imports, and shared utility behavior.plotly.express— high-level chart functions that normalize user data and build figures.plotly.ioandplotly.offline— JSON/HTML rendering, static image export, renderer selection, and notebook/file display.codegenandtemplategen— build-time generation for graph object classes, validators, and built-in templates.jsandplotly/labextension— Jupyter widget frontend integration.
Critical state is file-based and bundled with the package rather than stored in a service database:
- codegen/…/plot-schema.json and plotly/…/_validators.json hold schema/validator metadata.
plotly/package_data/**holds bundled Plotly.js, widget bundle, datasets, and template JSON.- Runtime figure state lives in Python graph-object instances created by users.
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.expresschart API that turns tabular inputs and semantic mappings into graph-object figures. - Figure factory — legacy helpers under
plotly.figure_factorythat construct specialized figures from domain-specific inputs. - Kaleido — the static image export backend used by
plotly.iofor 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/**, whileplotly/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/, andtemplates/. - 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/**, andtests/test_plotly_utils/**; route test-only changes using the same subsystem paths in the table below.
Routing table
-
plotly/graph_objects/**-> docs/graph-objects-data-model.md -
plotly/graph_objs/**-> docs/graph-objects-data-model.md -
plotly/validators/**-> docs/graph-objects-data-model.md -
plotly/validator_cache.py -> docs/graph-objects-data-model.md
-
tests/test_core/**graph-object, figure, update-object, or validator behavior -> docs/graph-objects-data-model.md -
plotly/shapeannotation.py -> docs/figure-subplots-callbacks.md
-
tests/test_core/test_subplots/**-> docs/figure-subplots-callbacks.md -
tests/test_core/test_update_objects/**-> docs/figure-subplots-callbacks.md -
plotly/express/**-> docs/plotly-express.md -
tests/test_optional/test_px/**-> docs/plotly-express.md -
tests/test_core/test_px/**-> docs/plotly-express.md -
any change to a
plotly.expresschart constructor or Express data-normalization behavior -> docs/plotly-express.md -
plotly/io/**-> docs/io-rendering-export.md -
plotly/package_data/**rendering assets, templates, datasets, or Plotly.js bundle changes -> docs/io-rendering-export.md -
tests/test_io/**-> docs/io-rendering-export.md -
any change to JSON, HTML, renderer, template, or Kaleido static export behavior -> docs/io-rendering-export.md
-
plotly/offline/**-> docs/offline-plotting.md -
tests/test_core/test_offline/**-> docs/offline-plotting.md -
any change to
plot,iplot, notebook initialization, or offline Plotly.js inclusion behavior -> docs/offline-plotting.md -
plotly/colors/**-> docs/colors-and-data-utilities.md -
plotly/data/**-> docs/colors-and-data-utilities.md -
plotly/optional_imports.py -> docs/colors-and-data-utilities.md
-
_plotly_utils/colors/**-> docs/colors-and-data-utilities.md -
_plotly_utils/data_utils.py -> docs/colors-and-data-utilities.md
-
_plotly_utils/optional_imports.py -> docs/colors-and-data-utilities.md
-
tests/test_plotly_utils/**utility/color/data tests -> docs/colors-and-data-utilities.md -
tests/test_optional/**optional dependency behavior outside Plotly Express -> docs/colors-and-data-utilities.md -
plotly/figure_factory/**-> docs/figure-factory.md -
tests/test_core/test_figure_factory/**-> docs/figure-factory.md -
any change to legacy factory helpers such as dendrogram, quiver, streamline, table, trisurf, ternary contour, or hexbin map -> docs/figure-factory.md
-
_plotly_utils/basevalidators.py -> docs/validator-framework.md
-
tests/…/test_basevalidators.py -> docs/validator-framework.md
-
tests/test_core/test_graph_objs/**validator/coercion behavior -> docs/validator-framework.md -
codegen/**-> docs/codegen-schema-pipeline.md -
plotly/…/_validators.json -> docs/codegen-schema-pipeline.md
-
any change to schema-to-Python generation, generated datatype layout, or validator generation -> docs/codegen-schema-pipeline.md
-
templategen/**-> docs/template-generation.md -
plotly/package_data/templates/**-> docs/template-generation.md -
any change to built-in template generation or theme definitions -> docs/template-generation.md
-
plotly/matplotlylib/**-> docs/matplotlylib-conversion.md -
any change to Matplotlib figure traversal or Matplotlib-to-Plotly conversion -> docs/matplotlylib-conversion.md
-
js/**-> docs/jupyter-widget-javascript.md -
plotly/labextension/**-> docs/jupyter-widget-javascript.md -
plotly/missing_anywidget.py -> docs/jupyter-widget-javascript.md
-
plotly/…/widgetbundle.js -> docs/jupyter-widget-javascript.md
-
tests/test_core/test_figure_messages/**-> docs/jupyter-widget-javascript.md -
any change to FigureWidget frontend messaging, Jupyter widget packaging, or labextension integration -> docs/jupyter-widget-javascript.md