Search code examples
pythonplotlytreemapstreamlitplotly-express

Plotly express treemap background color


I'm using plotly express treemap, I have different things to plot with preassigned colors. When there is no coincidence between both of the colors in the same section or subplot, the color of the section is assigned automatically to orange. How can I change that change that orange background color to another, for example white?

Example of the code, here "un", "conjunto" and "activo" are the sections of the treemap:

fig = px.treemap(df_prueba,
        path=[px.Constant(ruta),'un','conjunto','activo'], 
        color='color',
        color_discrete_map={'rojo':'red', 'verde':'#00b200', 'amarillo':'yellow',
            'gris':'#989898', 'azul':'blue', 'blanco':'white'},
        width=1400, height=700)

fig.update_traces(root_color='lightgrey')
        
st.plotly_chart(fig, use_container_width=False)

enter image description here


Solution

  • The parameter color_discrete_sequence=[new_color] setted before calling color_discrete_map solved the problem.It changes that random orange color to a new color for ex: new_color = "purple" .