plotly.py
plotly.py copied to clipboard
Force aspect ratio in subplots for example square
I have to do a plot with many subplots that sometimes have a weird layout (like a triangular hexagon of plots with different x and y total sizes). And I need all subplots to always be squares. It would be nice to be able to control the aspect ratio of individual subplots instead of relying on having to make grossly innacurate corrections to the total width and height of the plot. https://community.plotly.com/t/setting-height-width-of-subplot/1861 had luck his layout is square.
Thanks for opening this issue, @bonfire27 You might find using constrain='domain' helpful. This will keep the aspect ratio as desired but can add whitespace between subplots.
Specifically regarding your suggestion, this would be a nice feature to have but unfortunately it's not currently on our roadmap. We invite you to try solving this by creating a Pull Request.
constrain='domain' Unfortunately has no influence for my case. I tried it on the x axis on the y and on both. Thanks for the attention
Along with constrain='domain' (on one axis if you know which one is going to be larger, or both to be safe) you need one of the axes to reference the other as its scaleanchor, ie:
fig.update_layout(yaxis_scaleanchor="x", yaxis2_scaleanchor="x2", ...)
scaleanchor doesn't control the subplot shape per se, it controls the relative scales of the x and y axes on the subplot. But then if you ALSO know that the ranges have matching span, that will ensure the subplots are square.
Currently that's the only mechanism we have to force square subplots, other than by properly calculating the domains based on (width minus horizontal margins) and (height minus vertical margins) - in which case you also need to ensure nothing (like legends or axis titles) automatically increases those margins.
Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson