Search code examples
matlabplotbar-chartlegendprecision-recall

How to add three legends of a bar graph in matlab?


i have a bar graph which calculates precession and recall for three different methods and represents them in three different colors, code i used is as follows

x=[0.4,0.31,0.21]
y=[0.45,0.38,0.27]
bar(x,y,0.1)
h = bar(x,diag(y),0.1,'stacked');
xlabel('precession')
ylabel('recall') 

enter image description here

i want to add a legend that should show maroon color is for indiscernible relation, green is for discernible relation and blue is for equivalence relation


Solution

  • Try this:

    legend('indiscernible relation','cernible relation' ,'equivalence relation')
    

    Colors will be automatically inserted to the legend