In Plotly Express, set the axis limits with range_x=[min, max] / range_y=[min, max] and switch to a log scale with log_x=True / log_y=True. On any figure, including graph_objects, use fig.update_yaxes(range=[0, 100]) and fig.update_yaxes(type="log"). The one catch: on a log axis, update_yaxes(range=...) takes powers of 10, so range=[0, 3] means 1 to 1,000. The code was written for Plotly 7.2 and also runs on Plotly 6.
Quick Example
import numpy as np
import pandas as pd
import plotly.express as px
# Simulated body and brain mass for 90 animals, spanning six orders of magnitude
rng = np.random.default_rng(7)
# brain grams at 1 kg body mass, and the largest body mass (log10 kg) in each group
groups = {"Mammals": (9.0, 3.6), "Birds": (7.5, 2.0), "Reptiles": (0.9, 3.0)}
animals = pd.concat([
pd.DataFrame({
"group": group,
"body_kg": (body := 10 ** rng.uniform(-2, top, 30)).round(3),
"brain_g": (base * body ** 0.72 * rng.lognormal(0, 0.35, 30)).round(2),
})
for group, (base, top) in groups.items()
], ignore_index=True)
fig = px.scatter(
animals, x="body_kg", y="brain_g", color="group", log_x=True, log_y=True,
range_x=[0.005, 10000], range_y=[0.01, 10000],
color_discrete_sequence=["#b5179e", "#4361ee", "#2a9d8f"],
labels={"body_kg": "Body mass (kg)", "brain_g": "Brain mass (g)", "group": ""},
title="Brain vs body mass on log-log axes",
)
fig.show()
Body mass runs from 0.011 kg to about 3,800 kg and brain mass from 0.04 g to about 6,400 g. On linear axes, almost every point would sit in the bottom-left corner. On log-log axes each group falls along a straight line, and the gap between the lines is a constant ratio: at the same body mass, the simulated reptiles have about a tenth of the brain mass of mammals. range_x and range_y take ordinary data values here, even though the axes are logarithmic.
Set the axis range
There are three equivalent ways to set an axis range, and they all take [min, max]:
| Where | x-axis | y-axis |
|---|---|---|
| Plotly Express call | range_x=[0, 10] |
range_y=[0, 100] |
| Any figure | fig.update_xaxes(range=[0, 10]) |
fig.update_yaxes(range=[0, 100]) |
| Layout | fig.update_layout(xaxis_range=[0, 10]) |
fig.update_layout(yaxis_range=[0, 100]) |
update_xaxes and update_yaxes change every x- or y-axis in the figure, which is what you want for facets. Pass row= and col= to change one subplot. yaxis_range only changes the first y-axis.
You can also leave one end open. range=[0, None] fixes the bottom at zero and lets Plotly pick the top, which is the usual fix when a line chart's y-axis doesn't start at zero:
days = pd.date_range("2025-01-01", "2025-12-31", freq="D")
weekly = pd.DataFrame({"week": days, "sessions": 46_000 + 3_000 * np.sin(2 * np.pi * days.day_of_year / 365)
+ rng.normal(0, 900, len(days))}).resample("W", on="week").mean().reset_index()
fig = px.line(weekly, x="week", y="sessions", title="Weekly sessions, y-axis starting at zero",
labels={"week": "", "sessions": "Average daily sessions"}, color_discrete_sequence=["#e76f51"])
fig.update_yaxes(range=[0, None])
fig.update_xaxes(range=["2025-01-01", "2025-12-31"])
fig.show()

By default Plotly would fit the y-axis to the data (about 42,000 to 49,600), which makes the 14% dip from spring to fall look like a collapse. Starting at zero shows it in proportion. Date axes take date strings, like the update_xaxes call above. fig.update_yaxes(rangemode="tozero") gives a similar result: it keeps autoscaling but always includes zero, so it still works after the data changes. rangemode="nonnegative" stops the axis from going below zero without forcing zero in.
Use a log scale
log_x=True and log_y=True in Plotly Express, or fig.update_xaxes(type="log") and fig.update_yaxes(type="log") on any figure. A log axis makes equal ratios equal distances, so exponential growth becomes a straight line. That makes the growth rate visible, which a linear axis hides:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
months = np.arange(1, 37)
users = 120 * 1.18 ** months * rng.lognormal(0, 0.06, months.size)
fig = make_subplots(rows=1, cols=2, subplot_titles=["Linear y-axis", "Log y-axis"], horizontal_spacing=0.12)
for col in (1, 2):
fig.add_trace(go.Scatter(x=months, y=users, mode="lines+markers", marker_size=4,
line_color="#264653", showlegend=False), row=1, col=col)
fig.update_yaxes(type="log", row=1, col=2)
fig.update_xaxes(title_text="Month")
fig.update_layout(title="Monthly active users growing 18% a month", height=420)
fig.show()

Users grow from 134 to about 47,000 over three years. On the linear axis the first 20 months look flat. On the log axis the line is straight because the growth rate never changes, and a slowdown would show up as the line bending down.
Why does my log axis show NaN×10^Infinity?
On a log axis, update_yaxes(range=...) and yaxis_range take the log10 of the limits you want:
# Show 10 to 100,000 on a log y-axis
fig.update_yaxes(range=[1, 5], row=1, col=2) # 10**1 to 10**5
fig.update_yaxes(range=[np.log10(10), np.log10(100_000)], row=1, col=2) # same thing
If you pass range=[10, 100000], Plotly reads it as 10^10 to 10^100000: the tick labels turn into NaN×10^Infinity and the data sits flat along the bottom of the chart. Plotly Express's range_x and range_y are the exception: they take data values and convert them for you when log_x or log_y is set, which is why the Quick Example could use range_y=[0.01, 10000].
Zero and negative values can't be shown on a log axis. Plotly drops them silently, without an error, so check (df["col"] <= 0).sum() if points seem to be missing. Plotly has no symmetric log ("symlog") axis. For data that crosses zero, plot it on a linear axis or transform it yourself, for example with np.sign(y) * np.log10(1 + abs(y)), and relabel the ticks.
Format log axis ticks
By default, a log axis labels some of the values between powers of 10, and it switches to SI suffixes (1k, 10k) for large numbers. dtick=1 labels only the powers of 10, exponentformat="power" writes them as 10², 10³, and dtick="D2" adds small labels at 2 and 5 between them:
fig = px.scatter(animals, x="body_kg", y="brain_g", color="group", log_x=True, log_y=True,
color_discrete_sequence=["#b5179e", "#4361ee", "#2a9d8f"],
labels={"body_kg": "Body mass (kg)", "brain_g": "Brain mass (g)", "group": ""})
fig.update_xaxes(dtick=1, exponentformat="power", showexponent="all")
fig.update_yaxes(dtick=1, tickformat=",~g")
fig.show()

The x-axis shows powers of 10, and the y-axis prints plain numbers with thousands separators (tickformat=",~g"). Other exponentformat values are "e" (1e+3), "E", "SI" (1k), "B" (1B for a billion), and "none". dtick on a log axis is in powers of 10, so dtick=2 labels every hundredfold step. Minor ticks between the labels are controlled by fig.update_yaxes(minor_ticks="outside").
Reverse an axis
autorange="reversed" flips an axis while keeping automatic limits. It suits depth, rankings, and other values where smaller should be higher. To reverse with fixed limits, give the range high-to-low, like range=[1000, 0]:
depth = np.arange(0, 1001, 10)
water = pd.DataFrame({"depth_m": depth,
"temp_c": 4 + 20 / (1 + np.exp((depth - 180) / 45)) + rng.normal(0, 0.1, depth.size)})
fig = px.line(water, x="temp_c", y="depth_m", title="Ocean temperature profile",
labels={"temp_c": "Temperature (°C)", "depth_m": "Depth (m)"},
color_discrete_sequence=["#1d3557"], width=520, height=520)
fig.update_yaxes(autorange="reversed")
fig.update_xaxes(side="top")
fig.update_layout(margin=dict(t=130, b=30))
fig.show()

"min reversed" and "max reversed" also exist: they reverse the axis and fix one end at the value in range while autoscaling the other.
Limit how far users can zoom and pan
The range only sets the starting view. Readers can still zoom and pan anywhere. To stop that:
fig.update_yaxes(fixedrange=True)locks the axis, so zooming and panning only move the other one. See disabling zoom on specific axes.fig.update_yaxes(minallowed=0, maxallowed=100)lets readers zoom but never past those limits.fig.update_yaxes(autorangeoptions=dict(minallowed=0))keeps autoscaling but never below 0, andautorangeoptions=dict(include=0)makes sure zero is in view.
minallowed, maxallowed, and autorangeoptions were added in Plotly 5.17. On older versions they raise ValueError: Invalid property specified for object of type plotly.graph_objs.layout.YAxis: 'minallowed'.
Which setting should I use?
| You want | Use |
|---|---|
| Fixed limits on a Plotly Express chart | range_x=, range_y= |
| Fixed limits on any figure or one subplot | fig.update_yaxes(range=[lo, hi], row=, col=) |
| The y-axis to start at zero | range=[0, None] or rangemode="tozero" |
| Data that spans several orders of magnitude | log_y=True or update_yaxes(type="log") |
| Larger values lower on the chart | autorange="reversed" |
| A view readers can't scroll away from | fixedrange=True or minallowed/maxallowed |
Practical Tips
- Start bar charts at zero. Bars are read by length, so a cut-off axis exaggerates differences. Line charts can start elsewhere when the change is the point.
- Say "log scale" in the axis title when you use one, since many readers assume linear.
- Set ranges per subplot with
row=andcol=when the panels have different scales. A bareupdate_yaxes(range=...)applies to every y-axis. - Check that nothing is cut off. Points outside the range aren't drawn and don't trigger a warning. In Matplotlib the same task is
set_xlimandset_ylim.
