Can I modify the default "color cycle order"?

This is a customization feature available in matlab and matplotlib (https://matplotlib.org/examples/color/color_cycle_demo.html), and I’m wondering if I’m using the wrong terminology to find this, or it’s just not available.

If I plot four line traces, by default they will use the “category10” colors, #1f77b4, #ff7f0e, #2ca02c, #d62728 (I think). Alternatively, I can set each trace color explicitly when I create it. What I want is to replace the figure’s color cycle list with a custom set, instead of the default category10, so the traces will use the colors from the custom set, in order, without being specified in the trace. Is this possible? This is useful for me because it allows me to maintain good separation between code that produces data for traces, and code that styles the traces.

My current “good enough” solution is this:

def set_color_cycle(traces):
    for n, t in enumerate(traces):
        color = color_cycle[n % len(color_cycle)]
        if 'line' not in t:
            t['line'] = {'color': color}

    return traces

Currently the colors are being read from a javascript file, so through Python alone you won’t be able to modify the default list.

What’s important to know is that there is a Plotly plotly.colors module which could be useful for you. It contains a copy of the default list of colors plotly.colors.DEFAULT_PLOTLY_COLORS which is just an list of rgb values of those same 10 you are using by default.

Some of the FigureFactories currently use this list to generate the colors, including Violin Plots, ScatterplotMatrix, Gantt Charts, and Trisurfs. For these kinds of charts, you can modify your own personal file of the default colors if you so desire.

Thanks! That’s about what I figured. Good to know about the colors module.

1 Like