Adding shape doesn't automatically adjust plot boundaries?

If I run the following:

fig=go.Figure()
fig.add_shape(type="rect",
    x0=10, y0=1, x1=8, y1=3,
    line=dict(color="RoyalBlue"),
)

The plot I get won’t show the rectangle on screen (I have to scroll to see it). When I do something like add_scatter, no matter what I draw, the axes are adjusted to show me all data on screen. Is there anyway to make sure add_shape adjusts axes? Should I be using something other than add shape? Thanks!

@johnc1231
You can get the shape as you expect, by setting axes range:

fig.update_layout(xaxis_range=[a,b], yaxis_range=[c,d])

where [a,b], [c, d] define the plot window where you want to place the shape.

Thanks @empet

The problem with that for me is that if I have something else plotted too, I don’t want to make the ranges smaller and unshow those things. Is there a way to tell a figure to get “at least this big” to make sure the rect is always shown without potentially making the ranges smaller?

@johnc1231

I know you have a trace to plot, but you can set the axes range such that to contain both the shape and one or more traces.

Sure, but say I don’t know what ranges to set? I’d like plotly to be able to figure this out by “zooming out” enough to show all the data points I plot.