0

I have a dataframe as you can see in the image. I want to add to my plot the error bars (this is "std" column).

I have only managed to plot the bars, but not the errors.

I checked this answer: enter link description here The answer uses a Facetgrid. I need a Factorplot.

Here is my code:

#Seaborn --ploteo de barras
sns.set(style="white")
g = sns.factorplot(x="Stage", y="Mean_Acc", hue='Clf', data=df, size=4, aspect=3, kind="bar",
               legend=False) 

g.set(ylim=(0, 120)) 
g.despine(right=False) 
g.set_xlabels("") 
g.set_ylabels("") 
g.set_yticklabels("") 



mylegend=plt.legend(bbox_to_anchor=(0., 1.1, 1., .102), prop ={'size':10}, loc=10, ncol=8, #left, bottom, width,
                title=r'BEST STAGE AFTER OPTIMIZATION')                                #height, loc='center'
mylegend.get_title().set_fontsize('24') 



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.apply(annotateBars, ax=ax, axis=1)

enter image description here

enter image description here

Aizzaac
  • 3,146
  • 8
  • 29
  • 61
  • Is there any reason to use a factorplot here, instead of a barplot? – ImportanceOfBeingErnest May 27 '17 at 21:11
  • I saw it. Can you give me a clue on how to make the error function? So that I can add it to my code. – Aizzaac May 27 '17 at 22:01
  • 1
    No I can't. Because this would involve inventing some data or typing in all your data manually and it would otherwise be the exact same code as in the linked question. If you can provide a [mcve] of the issue that has the code from the linked question incoorporated, you can update your question with it and me or someone else can help you. – ImportanceOfBeingErnest May 27 '17 at 22:08
  • I am just asking for clue. And as you see in the linked question; despite he did not give a "Minimal, Complete, and Verifiable example"; he received help. – Aizzaac May 27 '17 at 22:18
  • Sure, but he was the first one to ask this question and he needed to wait 3 days for an answer. There is no difference between using a factorplot and a Facetgrid (a factorplot produces a Facetgrid). You also did not answer my question why to use a factorplot at all. I wouldn't know which clue to give you other than using the linked solution. – ImportanceOfBeingErnest May 27 '17 at 22:38
  • Because I am plotting numeric classes and non numeric. Barplots are only for numeric classes. – Aizzaac May 29 '17 at 14:55
  • `sns.barplot` is for categorical data. `pyplot.bar` can only work with numeric data. In the latter case you can easily get numerical data by enumerating the dataframe column, (`range(len(df["column"]))`). But in any case the duplicate question's answer shows how to use a FacetGrid and give you the desired result. You can of course ask a new question but always be very specific about what you need and in how far other questions are not helping. – ImportanceOfBeingErnest May 29 '17 at 16:47

0 Answers0