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

Plotly · Module

fig.update_traces

Updates properties on one or more Plotly figure traces. Selectors and subplot coordinates let you limit which traces are changed.

How it works

Call this method on a Figure to apply trace-property changes to every trace matching the optional selector and subplot filters. Nested properties are merged recursively by default; pass overwrite=True to replace the existing nested property structure instead.

Syntax

fig.update_traces(patch=None, selector=None, row=None, col=None, secondary_y=None, overwrite=False, **kwargs) → plotly.graph_objects._figure.Figure

Parameters

NameTypeDescription
patchdict or NoneDictionary of property updates applied to every trace satisfying the selection criteria; defaults to None.
selectordict or NoneSelection criteria used to choose which traces receive the update; defaults to None.
rowint or NoneSubplot row restricting which traces are updated; defaults to None.
colint or NoneSubplot column restricting which traces are updated; defaults to None.
secondary_ybool or NoneWhether the selected traces belong to a secondary y-axis; defaults to None.
overwriteboolWhether to replace rather than recursively merge existing nested properties; defaults to False.
kwargsdictAdditional trace properties to update, supplied as keyword arguments.

Returns

plotly.graph_objects._figure.Figure

Key points

  • The method belongs to Plotly graph-object Figure instances and changes one or more traces in place.
  • A single call can modify multiple properties across multiple selected traces.
  • Use selector to target traces by matching their properties instead of changing every trace.
  • Use row and col to constrain changes to a particular subplot location.
  • When subplot coordinates are supplied, traces outside that row and column are excluded.

Common mistakes

  • A selector that does not match a trace leaves that trace unchanged.

Example: Update matching traces

import plotly.graph_objects as go

fig = go.Figure()
fig.add_scatter(y=[1, 3, 2], name="first")
fig.add_scatter(y=[2, 1, 4], name="second")
fig.update_traces(line=dict(width=3), selector=dict(type="scatter"))
fig.show()

Creates two scatter traces and updates the line width of every scatter trace.

When to use it

Batch trace styling

Apply shared styling such as line width, marker color, or opacity to a group of traces.

Selective trace editing

Change only traces matching a property such as type or name.

Subplot-specific updates

Modify traces belonging to one subplot in a multi-panel figure.

Interview questions

QWhat does Figure.update_traces do, and how can its scope be limited?

update_traces applies keyword property updates to all traces satisfying the supplied selection criteria. The selector can filter traces by properties, while row and col restrict updates to a subplot.

Follow-up: How would you update only the second scatter trace? Use a selector matching a trace property such as name, for example selector=dict(name="second").

QWhat are patch, kwargs, and the return value?

The patch argument supplies a dictionary of property updates for matching traces. Keyword arguments are also accepted, and the method returns the Figure object so calls can be chained.

Follow-up: When would patch be preferable to direct keyword arguments? Use it when the update mapping is built dynamically or when you want to pass a reusable dictionary.

QHow does overwrite affect nested trace updates?

Nested updates are recursive by default, so unspecified nested properties remain in place. Setting overwrite=True changes this behavior and replaces the existing nested property structure with the supplied update.

Follow-up: What risk comes with overwrite=True? Any nested settings omitted from the replacement structure may be discarded.

  • Figure.update_layout
  • Figure.update_xaxes
  • Figure.update_yaxes
  • Figure.select_traces

Source: plotly.graph_objects.Figure.update_traces — 7.1.0 documentation. Checked 2026-10-15.