Fine-grained chart construction
You need exact trace or layout control beyond a high-level chart helper.
Plotly · Module
plotly.graph_objects is Plotly’s low-level Python interface for constructing figures from traces, layouts, and related graph-object classes. Its Figure objects support validation, manipulation, rendering, and serialization.
The module provides automatically generated Python classes for the non-leaf parts of Plotly’s figure schema, including Figure, Layout, and trace types. Construct or update these objects, access properties with attributes or keys, and render or serialize the resulting figure.
import plotly.graph_objects as go| Name | Type | Description |
|---|---|---|
data | list|tuple|trace | Trace specifications, supplied as a list, tuple, or single trace instance. |
layout | Layout|dict | Layout specification passed to the Layout constructor. |
frames | list|tuple | Animation-frame specifications. |
skip_invalid | bool | Whether invalid properties are silently skipped. |
A hierarchy of graph-object instances representing a Plotly figure; rendering and serialization are provided by Figure methods.
import plotly.graph_objects as go
fig = go.Figure(
data=[go.Bar(x=["A", "B", "C"], y=[2, 5, 3])],
layout=go.Layout(title="Example")
)
fig.show()Creates a Figure from a graph-object trace and layout, then renders it.
You need exact trace or layout control beyond a high-level chart helper.
You want to add, remove, or update traces after creating a figure.
You need a structured figure representation for export or transport.
question
Follow-up: How can a graph-object figure be converted for storage or transport? Use methods such as to_dict() or to_json(), depending on whether a Python dictionary or serialized JSON is needed.
It provides the low-level building blocks for Plotly figures: traces, layouts, and the Figure class. The module uses an automatically generated hierarchy of Python classes that corresponds to the figure schema.
Follow-up: Why might you choose graph_objects over Plotly Express? It gives more direct control over individual traces and layout properties, while Plotly Express creates complete figures through a higher-level API.
Figure accepts data, layout, and frames specifications, which may be supplied using graph objects or dictionaries. The resulting figure can then be manipulated with methods such as add_trace() and update_layout().
Follow-up: What does skip_invalid do in the Figure constructor? When enabled, invalid properties in the figure specification are skipped silently rather than causing validation to fail.
plotly.expressplotly.graph_objects.Figureplotly.graph_objects.FigureWidgetplotly.graph_objects.Layoutplotly.graph_objects.Scatterplotly.graph_objects.Bar