✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Spacing between plot line and zero axes

Hi. I’d like to figure out how to change spacing distance between zeroline and plot line (shown on applied image). Sorry for such question. I’m just started using plotly so maybe I’m missed something.

Any help will ne appritieted.

Hello, and thank you for using the community forum!

The plotly.py library does some work in the background to compute this distance automatically, so if you want to change it I think that you will have to manually set the axis range of your figure. This will over-ride the built in autorange behavior.

You can do this by using the update_xaxes() function and the range attribute. For example, look at these two charts. Note that there is more distance between the first marker that is drawn and the y-axis in the first figure because it has a wider range.

import plotly.express as px
df = px.data.iris()

fig = px.scatter(df, x="sepal_width", y="sepal_length")
fig.update_xaxes(range=[1, 4.5])


fig.update_xaxes(range=[1.5, 4.5])