Set titles, dimensions, and margins for a polished figure.
Presentation charts
Plotly · Module
Updates a Plotly figure's layout-level properties, including titles, dimensions, margins, axes, legends, and interaction settings. Properties can be passed as nested dictionaries or compound keyword arguments.
Call this method on a Figure to change layout-level chart properties such as the title, dimensions, margins, axes, legend, colors, and interaction settings. Pass properties as keyword arguments; nested layout objects use dictionaries, and compound properties can also be addressed with underscore-separated keyword names.
fig.update_layout(dict1=None, overwrite=False, **kwargs)| Name | Type | Description |
|---|---|---|
**kwargs | layout property keywords | Layout properties supplied as keyword arguments, including title, dimensions, margins, axes, legend, and other figure-level settings. |
The updated Figure object.
title keyword.title_text compound property.width to set the plot's horizontal size in pixels.height to set the plot's vertical size in pixels.transition configuration for animated updates.import plotly.graph_objects as go
fig = go.Figure(go.Scatter(x=[1, 2, 3], y=[2, 1, 3]))
fig.update_layout(
title="Example chart",
width=700,
height=400,
margin=dict(l=50, r=20, t=60, b=40),
)
fig.show()Creates a figure, then changes its title, dimensions, and margins before displaying it.
Presentation charts
Responsive dashboards
Interactive analysis
fig.update_layout change?fig.update_layout modifies properties stored in the figure's layout. It accepts layout attributes such as title, width, height, and margin as keyword arguments.
Follow-up: How would you configure a nested axis property? Pass a dictionary such as xaxis=dict(title='Time'), or use a supported compound keyword such as xaxis_title='Time'.
Use width and height for plot dimensions in pixels, and use margin with keys such as l, r, t, and b to control surrounding space. The layout reference documents these properties and their defaults or constraints.
Follow-up: How can you make the dimensions responsive instead? Use the layout's autosizing behavior rather than forcing fixed width and height values.
Layout properties can be supplied in nested dictionaries, as shown by the documented title=dict(...) form. This is useful when configuring structured objects with multiple related attributes.
Follow-up: What is the alternative for a simple title string? Supply title='Example chart' or use the documented title_text layout property.
plotly.graph_objects.Figure.update_layoutlayouttitletitle_textwidthheightmargintransition