[Python] Custom color palette in seaborn

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

  1. Stack

    Stack Membro Participativo

    I have a scatterplot that should show the changes in bond lengths depending on temperature. I wanted to give each temperature a specific color, but it doesn't seem to work - plot uses the default seaborn palette. Is there a way to map temperature to color, and make seaborn use it?

    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns

    palette = ["#090364", "#091e75", "#093885", "#085396", "#086da6",
    "#0888b7", "#08a2c7", "#07bdd8", "#07d7e8", "#07f2f9",
    "#f9ac07", "#c77406", "#963b04", "#640303"]

    sns.set_style("whitegrid")
    sns.set_palette(palette)
    plot = sns.scatterplot(df.loc[:,'length'],
    df.loc[:,'type'],
    hue = df.loc[:,'temperature'],
    legend = False,
    s = 200)

    Continue reading...

Compartilhe esta Página