Plotly graph_object custom colors based on values :3

Hi everyone,

So this is something that I have been trying to figure out for a long time. I have been trying to look for a way to create custom coloured pie graph that is also tied to the value. The reason why I’m trying to figure this out is because I have a subplot with 3 pie charts. That also has scalegroup… to show who’s one has the larger sum.

Typically what I’m asking isn’t hard to do in Plotly Express.

colour_list = [ #some list of hex colours]
colours = dict(zip(df["Kawaii Score"], colour_list))

fig= px.pie(
            df,
            values="Kawaii Score",
            color="Kawaii Type",
            names="Kawaii Type",
            color_discrete_map=colours,
        )

However for plotly graphs_object I can’t quite find a method that does something similar. Best I can find is a custom colour that is not tied to the value. The issue now is if let us say UwU > OwO in one graph and in another uwu < owo then the colours will end up swapping. Then if you got :3 as well then all the colours all swap around.

as far as I’m aware this is the way to have custom colours in plotly graph object.

fig.add_trace(
            go.Pie(
                labels=df["Kawaii Type"],
                values=df["Kawaii Score"],
                name=df["Kawaii Type"],
                hole=0.5,
                scalegroup="kawaii_group",
                marker_colors=["#cdb4db", "#ffc8dd", "#ffafcc", "#bde0fe", "#a2d2ff"],
            ),
            1,
            1,
        )