✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Changing default color palette in Plotly Go? Python, Sunburst

I’m constructing a series of sunburst graphs using plotly.go.Sunburst and would like to change to a different discrete color scheme. The documentation makes this seem easy when using plotly express (default plotly palette is px.colors.qualitative.Plotly), but there is no information on how to change to a different custom color palette/swatch using go.Sunburst since it lacks a color_discrete_sequence= argument.

Does anyone know how I can change the default color palette? The inputs and categories vary based on end-user choices in the dashboard i’m building, so hard-coding color handling would be a huge pain in the ass. If I can just feed in an array of hex or rgb values to replace the default Plotly palette that would be ideal.

Though not the solution I had hoped for, there is a work-around using the plotly.io library to establish a custom layout theme. (reference documentation)

Example code:

import plotly.io as pio

# naming a layout theme for future reference
pio.templates["google"] = go.layout.Template(
    layout_colorway=['#4285F4', '#DB4437', '#F4B400', '#0F9D58',
                     '#185ABC', '#B31412', '#EA8600', '#137333',
                     '#d2e3fc', '#ceead6']

# setting Google color palette as default
pio.templates.default = "google"