colorsseabornpalettehistplot

seaborn multiple histplot color palette


The following example code:

import seaborn as sns
planets = sns.load_dataset("planets")
sns.histplot(
    planets, x="year", y="distance",
    bins=30, discrete=(True, False), log_scale=(False, True),
)

produces this plot enter image description here

How can I change the color palette being used here? I'd like to use something like sns.color_palette("Spectral", as_cmap=True) to show more clear contrast of different levels (the plot I really want has a larger number of histograms than this example, and it's hard to see the contrast with only blue hues)


Solution

  • You can use the cmap parameter

    sns.histplot(
        planets, x="year", y="distance",
        bins=30, discrete=(True, False), log_scale=(False, True),
        cmap="Spectral", cbar=True,
    )
    

    enter image description here

    But note that Spectral specifically is a diverging palette and not really appropriate for count data.