Streamlit overrides colours of plotly chart


Ok, so the issue is the following: since version 1.15.2, Streamlit seems to override colours of any created plotly figure, which breaks its rendering when its not done via Streamlit itself (for example, fig.to_html())

Consider the following code:

import streamlit as st
import pandas as pd
import numpy as np
import as px

x_axis = list(range(4))*2
data = np.array([["a", "b"]*4, x_axis, [2, 4, 3, 5, 7, 5, 8, 6]]).transpose()
df = pd.DataFrame(columns=["cat_value", "x", "y"], data=data)
fig =, x="x", y="y", color="cat_value", barmode="group")
for go_data in

On Streamlit 1.15.0 this code would generate the following output in logs:


and produce nice figure with blue and red bars. But if I update Streamlit to 1.15.2 or higher (pandas and plotly versions remain the same), figure will be the same, but text output will be the following:


which essentially means that if generated figure is to be rendered in any way other than st.plotly_chart, all markers will be black. It seems that Streamlit overrides color of created figure and then swaps it for something else while rendering.

My question is: there any way to create a figure with proper colours while running a script from Streamlit? For example, I need to render it via to_html().

If there is no such way now, maybe it should be fixed?

1 Like

Look at the theme argument to plotly_chart.

The thing is, by the time plotly_chart is called, figure is already created and therefore colours are already wrong, so this wont help

Oh, I see. I read your post too quickly. I would call that a bug. There is probably a way to work around this but I don’t know what it could be.

Hi @skyhound , sorry for just noticing this. We are indeed currently changing the underlying theme colors and then swapping them out. This is so that we can change based on light or dark themes in order to make the user experience much better!

However, if you wish to change the colors to the plotly colors instead of the black,

you can put this in your script:

import as pio
pio.templates.default = "plotly"

If you need to run to_html(), I think you can run the above and then do as such and well just replace whatever you need with to_html():

import as pio
import streamlit as st
import as px

pio.templates.default = "plotly"

df =
fig = px.scatter(
    title="streamlit colors",

Thank you very much! That works as a solution, at least if one is okay with default plotly colours.