I'm not sure if this is possible with Seaborn or if I have to transform my data first. I want a barplot (or catplot) with grouped bars. The keypoint is that the elements in the groups are corosponding to column names and not to values.
That is the data
Year Gin Beer
0 2016 84 78
1 2017 75 30
2 2018 42 47
3 2019 25 58
4 2020 51 90
5 2021 40 50
And that is my desired output:
From the Seaborn logic "combined" with my logic I would like to do something like this where I specify the column names in y=
argument.
sns.catplot(data=a, x='Year', y=['Gin', 'Beer'])
Can I realize it without touching the data or do I have to transform the data somehow?
This is the MWE
#!/usr/bin/env python3
import random as rd
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
sns.set_theme()
rd.seed(0)
a = pd.DataFrame({
'Year': [2016, 2017, 2018, 2019, 2020, 2021],
'Gin': rd.choices(range(100), k=6),
'Beer': rd.choices(range(100), k=6)
})
print(a)
# sns.catplot(data=a, x='Year', y=['Gin', 'Beer'])
# plt.show()