I am trying to change how the colours are displayed when plotting a grouped barplot with seaborn.
In the following minimal example,you get the output you would expect, the colour being set on the group. However, I want the colour to be set based on the category.
import pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltdata = [3, 5, 2, 4, 6, 1]group = [1, 2, 1, 2, 1, 2]category = ['a', 'a', 'b', 'b', 'c', 'c']data = pd.DataFrame(zip(category, group, data), columns=['category', 'group', 'data'])palette = sns.color_palette("pastel")fig, ax = plt.subplots(figsize=(15, 15))sns.barplot(data=data, x='category', y='data', palette=palette, hue='group', edgecolor='k', zorder=3, ax=ax)ax.grid(zorder=0)plt.tight_layout()plt.show()
I attempted to use a custom palette where each colour is repeated twice, but it still colours by the group and therefore displays with the same colour for all bars.
palette = [color for color in sns.color_palette("pastel") for _ in range(2)]
Is it possible to change the colouring to have the colour set on the category and not the group with Seaborn?