Same color theme for seaborn plots

163 Views Asked by At

I realized there are different color styles used for subplots that all are built upon the seaborn library (check the picture).

Anyone knows how to get the same ...

  • edgecolor,
  • transparency of the filling and
  • filling color ...

for sns.boxenplot, sns.boxplot and sns.histplot?

This is my code:


import seaborn as sns
sns.set(style='whitegrid')
sns.set_palette('pastel')


def boxenplot_boxplot_histo(data, feature, bins = None):
    # Create a figure and three subplots
    fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True, figsize=(7,4))

    # Subplot 1: Boxen Plot
    sns.boxenplot(data=data, x=feature, ax=ax1)

    # Subplot 2: Box Plot
    sns.boxplot(data=data, x=feature, ax=ax2)

    # Subplot 3: Histogram
    sns.histplot(data, x=feature, ax=ax3, bins=10, edgecolor='darkgrey')


    plt.show()

data = sns.load_dataset("tips")
boxenplot_boxplot_histo(data, 'total_bill')

enter image description here

I tried using the saturation parameter for both the boxenplot and boxplot --> but that parameter is not available for the histplot.

    # Subplot 1: Boxen Plot
    sns.boxenplot(data=data, x=feature, ax=ax1, saturation=1)

    # Subplot 2: Box Plot
    sns.boxplot(data=data, x=feature, ax=ax2, saturation=1)

also tried make configurations with the boxprops parameter for the boxplot but again, that's not available for sns.boxenplot.

sns.boxenplot(data=data, x=feature, ax=ax1, saturation=1, boxprops=dict(alpha=0.75))
1

There are 1 best solutions below

0
On

These functions have slightly different parameterizations and defaults but here's how you can make them look more consistent:

data = sns.load_dataset("tips")
spec = dict(data=data, x="total_bill")
ec = "darkgray"

fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True, figsize=(7,4))

sns.boxenplot(**spec, ax=ax1, linewidth=1, linecolor=ec, flier_kws={"edgecolor": ec}, saturation=1)
sns.boxplot(**spec, ax=ax2, linewidth=1, linecolor=ec, saturation=1)
sns.histplot(**spec, ax=ax3, linewidth=1, edgecolor=ec, alpha=1)

The main thing is that the color is slightly desaturated by default in boxenplot and boxplot, whereas is it slightly transparent in histplot.

enter image description here