Legend in a bar plot in Matlab

前端 未结 2 1669

How can I plot a legend in a bar plot in Matlab? Here is the code:

Y = [1.5056
0.72983
3.4530
3.2900
1.4839
12.9 ];
n = length(Y);
h = bar(Y);
colormap(summer(n)         


        
2条回答
  •  甜味超标
    2021-02-03 16:03

    Further to bla's answer, you can use

    h = bar(diag(Y),'stacked');
    

    if you want to avoid the displacement.

提交回复
热议问题