I have a dataframe that I want to plot. I have thought of 2 options (check the images).
For OPTION 1, I need to annotate a categorical value (the "Elec").
For OPTION 2, I still need to use "factorplot", but I do not know how to fix the error I get.
#CODE FOR THE DATAFRAME
raw_data = {'Max_Acc': [90.71, 87.98, 92.62, 78.93, 73.69, 73.66, 72.29,
92.62, 94.17, 92.62, 83.81, 79.76, 74.40, 72.38],
'Stage': ['AWA', 'Rem', 'S1', 'S2', 'SWS', 'SX', 'ALL',
'AWA', 'Rem', 'S1', 'S2', 'SWS', 'SX', 'ALL'],
'Elec': ['Fp1', 'Fp2', 'C4', 'Cz', 'Pz', 'P4', 'T3',
'C4', 'T3', 'Fp1', 'P4', 'Fp2', 'Fz', 'Fz'],
'Clf': ['RF', 'RF', 'RF', 'RF', 'RF', 'RF', 'RF',
'XG', 'XG', 'XG', 'XG', 'XG', 'XG', 'XG']}
df_m=pd.DataFrame(raw_data, columns = ['Max_Acc', 'Stage', 'Elec', 'Clf'])
df_m
#CODE FOR THE PLOT (OPTION 1)
sns.set(style="white")
g = sns.factorplot(x="Stage", y="Elec", hue='Clf', data=df, size=2, aspect=3, kind="bar",
legend=False)
ax=g.ax
def annotateBars(row, ax=ax):
for p in ax.patches:
ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()),
ha='center', va='center', fontsize=11, color='gray', rotation=90, xytext=(0, 20),
textcoords='offset points')
plot = df_m.apply(annotateBars, ax=ax, axis=1)
#CODE FOR THE PLOT (OPTION 2)
g = sns.factorplot(x="Clf", y="Max_Acc", hue='Elec', col='Stage', data=df, size=2, aspect=3, kind="bar",
legend=False)
OPTION 1 (Annotating with categorical values)
OPTION 2 (Plotting 4 variables)