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

Plotly · Module

fig.update_xaxes

Updates layout properties on one or more x-axes in a Plotly graph-object figure. It can apply broadly or target a subplot with row and col selectors, and returns the modified figure.

How it works

Call this graph-object figure method with keyword arguments matching layout.xaxis properties. The update applies to the figure’s x-axes, and optional row and col selectors can limit the target axes in subplot figures; the method returns the modified figure reference for chaining.

Syntax

fig.update_xaxes(patch=None, selector=None, overwrite=False, row=None, col=None, **kwargs)

Parameters

NameTypeDescription
**kwargsxaxis property valuesAxis layout properties such as title_text, range, showgrid, visible, type, and tick settings; these are passed as keyword arguments.
rowint or NoneSelects the subplot row whose x-axis should be updated.
colint or NoneSelects the subplot column whose x-axis should be updated.

Returns

A reference to the figure being modified.

Key points

  • Use update_xaxes on graph-object figures to configure x-axis layout properties after chart creation.
  • A single call can modify several nested axis settings and can target one or multiple axes.
  • The method returns the modified figure reference, enabling fluent updates.

Common mistakes

  • For logarithmic x-axes, range values are exponents rather than the displayed numeric endpoints.
  • tickvals does nothing unless tickmode is configured as array.

Example: Hide x-axis grid lines

import plotly.express as px

df = px.data.iris()
fig = px.scatter(
    df,
    x="sepal_width",
    y="sepal_length",
    color="species",
    facet_col="species",
)
fig.update_xaxes(showgrid=False)
fig.show()

Creates a faceted scatter plot and hides the grid on every x-axis.

When to use it

Configure grid lines, visibility, titles, or tick styling

Apply consistent styling across a figure or all subplots.

Target a specific subplot with row and col

Change only one subplot’s x-axis.

Set ranges and linear or logarithmic axis types

Control displayed data bounds and scale behavior.

Interview questions

QWhat does fig.update_xaxes do?

It updates one or more x-axis layout properties on a graph-object figure, such as title, range, visibility, grid, and tick settings. The keyword arguments correspond to layout.xaxis attributes.

Follow-up: How would you target one subplot? Pass row and col, for example fig.update_xaxes(title_text="x", row=1, col=2). The selectors restrict the update to that subplot axis.

QHow does it behave with subplots?

By default, the method updates all x-axes in the figure. In subplot figures, row and col can select the axes associated with a particular subplot.

Follow-up: How can you update only axes satisfying a condition? Use the related for_each_xaxis method to apply logic across selected axis objects.

QWhat does the method return?

The method returns a reference to the figure being modified, so calls can be chained or the result can be assigned. It mutates the figure’s axis configuration rather than creating a separate chart.

Follow-up: What changes for a logarithmic axis range? Supply logarithmic exponents—for example, range=[0, 5] represents values from 1 through 100000.

  • fig.update_yaxes
  • fig.for_each_xaxis
  • fig.for_each_yaxis
  • layout.xaxis

Source: Creating and Updating Figures. Checked 2026-10-15.