I am trying to do a barplot with seaborn but I am having some issues.
Here is an example of my dataset:
df = pd.DataFrame([[1, 'C1', 5],
[2, 'C1', 18],
[3, 'C1', 33],
[1, 'C2', 10],
[2, 'C2', 10],
[3, 'C2', 19],
[0, 'BG', 4]])
df.columns = ['trial', 'type', 'value']
Palette = ['#A9A9A9', '#228B22', '#DC143C']
sns.barplot(data = df, x = 'trial', y = 'value', palette = Palette, hue = 'type')
plt.xticks(ticks = range(0, 4), labels = ['0', '1', '2', '3'])
plt.ylim(0, 100)
The issue that I’m having is that when I run this code I get a plot where the bars are off-centered:
Since I don’t have the same amount of bars for each trial, I would like them to be centered based on the amount of bars that I have for that trial and not the total amount of bars.
If I use dodge = False
this is the result I get: