Enforce constant graph area dimensions

I need to generate a series of scatterplots with constant size of the plotting area. How to ensure the legend, title, axis titles, tick labels etc. won’t change the plotting area?

import plotly.express as px

fig = px.scatter()
fig = fig.add_scatter(x=[1], y=[1])
fig['data'][1]['name']='very long string this is way too long string for a name very long string this is way too long string for a name very long string this is way too long string for a name'
fig = fig.add_scatter(x=[3], y=[3])
fig = fig.update_layout(width=1200)
fig

E. g. in this example the long legend pushes the plotting area away.
I am aware of this solution: Avoid legend automatically repositioning
But I need to ensure that all the other elements won’t change the size of the graph area as well. Is there a way for doing this? This seems like a very fundamental feature so please don’t tell me it’s not possible in plotly…

:wave: Hi! Fine tuning chart it’s the most time-consuming part of the task at least for me, so maybe if you share the full data (or at least) some toy data and seeing how it looks I could reproduce it. Because, I didn’t figure out the problem yet…

Hey, thanks for your reply. The example in my question illustrates it actually, but let me reword the issue.

I want to be able to guarantee that the graph are is a certain size, no matter what the other features of the figure are (e. g. big title, long legend). As you see in the example, the legend pushes the graph to the left. I want to control the size of the plotting area and ensure that e.g. it’s always 400x800 px big, so that I can generate multiple plots with different legend lengths, but identical position of the graph area.

:blush: Ok, now I see it!! First, try this fig.update_layout(legend_orientation='h') and it will put your legend at the bottom of the chart. Another thing, could be creating a dictionary for the names of the traces, but it will need a little bit more of creative works. What do you think?

I’ve considered workarounds like this, but this particular one just shifts the problem from x axis to y. What if I have twenty legend entries? The plot would be then squeezed to the top of the figure. I need to specify/hardcode the plotting area size directly, regardless of size/number/position of all other elements. But thanks anyway