not necessarily a question rather a workaround I found for using Plotly charts in Streamlit apps.
When I use Plotly without any sizing guidance, legend usually covers the chart and it is oddly distorted.
Moreover, it often overlaps with the st.subheader() and other elements below it.
My workaround was to set the size of the chart twice:
once in the Plotly object (eg, fig.update_layout(width=1100,height=900) ) - this one actually changes the size of the plot, so it’s readable
and then in the Streamlit command (eg, `st.plotly_chart(fig,width=1100,height=900) ) - this one moves all the subsequent elements below the Plotly chart (no more overlapping!)
I’ve tried using only the Streamlit command, but it wasn’t actually changing the Plotly figure size.
I didn’t even realize that was an option, just thought the size of my plotly charts was off…here is an example – with this code (I can provide more if needed)
Providing a full example would be helpful, as it’s not clear to me what your question is. Are you expecting both charts to be the same size, persisting the height across calls?
Hi @randyzwitch,
Yes, in my example, I’m expecting both charts to be the same size.
And now that I rechecked this, they both are the same size when I run locally, but when I deploy to heroku, the second chart (st.plotly_chart(fig)) gets resized back down…so it may be a separate issue.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.