Overriding new streamlit theme - how to modify plotly title and axis labels?

Summary

My app includes many plotly graphs using st.plotly_chart. I am now auto-using the streamlit theme since I like how it looks. However, I am finding it impossible to adjust any of the title or axis labels, in terms of size, colour, position, etc. I want to keep using the streamlit theme because it looks much much better than the plotly themes. But, it’s very important that I can control the size, colour, placement, etc. otherwise the theme is unusable.

Steps to reproduce

Code snippet:

        fig.update_layout(title=dict(font=dict(size=40)))
        fig.update_layout(title_font_size=40)
        fig.update_layout(
        title={
            'text': "Plot Title",
            'y':0.9,
            'x':0.9,
            'xanchor': 'right',
            'yanchor': 'top'})
        fig.update_layout(
        title="Plot Title",
        xaxis_title="X Axis Title",
        yaxis_title="Y Axis Title",
        legend_title="Legend Title",
        font=dict(
            family="Courier New, monospace",
            size=18,
            color="RebeccaPurple"
        )
        )
        fig.update_layout(
        title=dict(
            text='<b>Life Expectancy - Our World in Data</b>',
            x=0.5,
            y=0.95,
            font=dict(
                family="Arial",
                size=20,
                color='#000000'
            )
        ))
        fig.update_layout(font={'size': 30})

Above are several example of the many types of updates I have tried to make to the layout in order to make any type of change, but it’s not working.

Expected behavior:

I expect that the title would be adjusted according to the normal plotly methods of updating labels.

Actual behavior:

Nothing is modified in my title or labels. The only thing that actually gets updated is my custom range selector of buttons (which I really don’t care about modifying). The text colour still stays as the textColor I have set in my config.toml file.

Debug info

  • Streamlit version: 1.17.0
  • Python version: 3.8.13
  • Conda
  • OS version: Mac
  • Browser version: Chrome/safari

Requirements file

altair==4.2.0
bokeh==3.0.3
boto3==1.24.28
nltk==3.7
pandas==1.4.4
plotly==5.9.0
vega_datasets==0.7.0
streamlit==1.17.0

Links

  • Link to your GitHub repo: private
  • Link to your deployed app: private

Hi @alaym3 , did you figure it out? I am facing the same problem, couldn’t change the title position from update_layout. Please let me know if you knew how to do, thanks!

Still couldn’t solve that problem. On jupyter notebook, the position of title is changing but on streamlit not.

I still have not figured it out - seems impossible unfortunately.

Hi @alaym3 @Usmanjon_Abduraimov , sorry I just noticed this!
I tried testing this out and this actually seems like a bug. I think I know why it’s being caused. Can you submit a bug report? However, this will be on my list of things to do hopefully today… I just tested out the fix for the title and it seems to work but I will look into the axis labels and get back to here.

Also, fyi that bug fix if it gets merged, it will get into the 1.18 release which would likely be next week… with some other huge updates! :slight_smile:

I just submitted this bug report :slight_smile: thank you very much @willhuang !!! :grin:

Thank you for posting about this! Otherwise I would have never known because I just happened to miss this! :frowning: Sorry for getting to this post so late… I wish I had seen it 6 days ago but I’m not AS active on the forum as things are ramping up in Snowflake :laughing:

Thank you very much @willhuang !!

Thank you @Usmanjon_Abduraimov for replying to this and bringing this thread up again! :slight_smile: It really makes me happy that you guys like the new streamlit theme… but makes me very sad that it’s not usable for x, y reasons! Will do my absolute best to make sure those x,y - if resolvable - are resolved :slight_smile: