[Python] seaborn ignores custom color palette when number of patches exceeds number of colors

Discussão em 'Python' iniciado por Stack, Julho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I set up a palette containing just black and gray as follows.

    import seaborn as sns
    sns.set_palette(['#000000', '#ABABAB'])


    This works fine if I just have two or less patches in my plot.

    sns.barplot([1, 2], [3, 4])


    [​IMG]

    However, when I have more bars than colors, seaborn switches back to the default palette.

    sns.barplot([1, 2, 3], [4, 5, 6])


    [​IMG]

    Can I make seaborn cycle through my custom color palette? In the case above, the first bar should be black, the second grey and the third one black again.

    My current workaround is

    sns.set_palette(['#000000', '#ABABAB']*1000)


    but I doubt this is the standard way to do it.

    Continue reading...

Compartilhe esta Página