Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Plotly · Module

fig.update_layout

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.

How it works

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.

Syntax

fig.update_layout(dict1=None, overwrite=False, **kwargs)

Parameters

NameTypeDescription
**kwargslayout property keywordsLayout properties supplied as keyword arguments, including title, dimensions, margins, axes, legend, and other figure-level settings.

Returns

The updated Figure object.

Key points

  • The method accepts a structured title object through the title keyword.
  • A title can also be set directly with the title_text compound property.
  • Use width to set the plot's horizontal size in pixels.
  • Use height to set the plot's vertical size in pixels.
  • Compound margin keywords let you set an individual margin, such as the top margin.
  • The layout can include a structured transition configuration for animated updates.

Common mistakes

  • Width must be at least 10 pixels according to the documented constraint.

Example: Configure a figure layout

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.

When to use it

Set titles, dimensions, and margins for a polished figure.

Presentation charts

Configure autosizing and layout spacing for embedded charts.

Responsive dashboards

Adjust axes, legends, hover behavior, transitions, and other figure-level controls.

Interactive analysis

Interview questions

QWhat does 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'.

QHow do you control figure size and whitespace?

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.

QHow are nested layout objects represented?

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_layout
  • layout
  • title
  • title_text
  • width
  • height
  • margin
  • transition

Source: Layout in Python. Checked 2026-10-15.