Set titles, dimensions, colors, fonts, margins, and legend placement.
Chart styling
Plotly · Function
Updates a Plotly figure's layout from a dictionary, keyword arguments, or both. Updates are recursive by default and the Figure object is returned.
Call update_layout on a Figure to change layout properties using either a dictionary, keyword arguments, or both. Nested dictionaries are merged recursively by default; set overwrite=True when the supplied values should replace existing nested properties.
Figure.update_layout(dict1=None, overwrite=False, **kwargs) → plotly.graph_objects._figure.Figure| Name | Type | Description |
|---|---|---|
dict1 | dict, optional | Dictionary of layout properties to update. |
overwrite | bool, optional | If True, overwrite existing properties; otherwise apply recursive updates while preserving unspecified properties. |
kwargs | keyword arguments | Keyword/value pairs of layout properties to update. |
The Figure object that update_layout was called on; return type BaseFigure.
import plotly.express as px
fig = px.scatter(x=[1, 2, 3], y=[3, 1, 2])
fig.update_layout(
title="Sample chart",
width=600,
height=400,
margin=dict(l=40, r=20, t=60, b=40),
)
fig.show()Creates a scatter figure, then changes several layout properties with keyword arguments and a nested margin dictionary.
Chart styling
Reusable configuration
Incremental customization
update_layout changes a figure's layout using a dictionary, keyword arguments, or both. It returns the same Figure object, so calls can be chained or followed by other figure operations.
Follow-up: How can nested properties be replaced rather than merged? Pass overwrite=True to replace existing properties instead of recursively applying the update.
The method recursively updates the existing layout structure by default. For example, supplying margin=dict(t=60) changes the top margin while preserving other existing margin values.
Follow-up: What happens if overwrite=True is supplied? Existing nested properties are overwritten by the supplied update rather than preserved when omitted.
The signature accepts dict1=None, overwrite=False, and arbitrary keyword arguments. dict1 contains properties to update, while kwargs provide property/value pairs such as title or width.
Follow-up: Can the dictionary and keyword forms be combined? Yes; both are accepted in the same call and contribute to the layout update.
Figure.update_tracesFigure.update_layout_imagesFigure.update_annotationsplotly.graph_objects.Layout