Black Lives Matter. Please consider donating to Black Girls Code today.

Size of background compared to Scatter

Why there is space left to 0 and right to 5 in

fig = go.Figure()
fig.add_trace(go.Scatter(x=[1,2,3,4,5], y=[1,2,1,2.5,1.5], mode='lines+markers'))
fig.show()

but not in

fig = go.Figure()
fig.add_trace(go.Scatter(x=[1,2,3,4,5], y=[1,2,1,2.5,1.5], mode='lines'))
fig.show()

? How to retrieve it?

Hum, probably because the marker has a finite size therefore plotly decides that it needs to extend the axis range so that markers can be seen entirely. You can retrieve the same space with the following workaround (yes, it’s a hack :-))

import plotly.graph_objects
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1,2,3,4,5], y=[1,2,1,2.5,1.5], mode='lines+markers', marker_opacity=0))
fig.show()
1 Like