Is this a bug? X scale jumps around when using mode='line+markers' vs just lines

I’ve spent the last week making a very detailed chart using mode=lines exclusively and noticed when I added a lines+markers Scatter plot suddenly the x scale jumps around when it’s toggled on and off. If this is intentional, it’s very annoying!

Simple example:

x = [1, 2, 3, 4, 5]
y = [2, 0, 4, 8, 3]
y2 = [8, 4, 0, 3, 2]

fig = go.Figure()
fig.add_trace(go.Scatter(
x=x,
y=y,
mode=‘lines’
))
fig.add_trace(go.Scatter(
x=x,
y=y2,
mode=‘lines+markers’
))
fig.show()


Hi,

I don’t think this is a bug, but autorange does work differently for markers and lines and some padding is added in the former case, as you have noticed. It can be annoying if you have a mixture of both types (“pure” lines with markers or lines+markers).

The easiest fix is to set the range manually with fig.update_xaxes(range=[min(x), max(x)]).

1 Like