如何在MATLAB中仅显示bar3绘图的选定图例条目?

时间:2013-11-10 13:44:28

标签: matlab plot

请考虑以下代码:

A=0:0.1:4;
for i=1:50,
    B(:,i) = sin(A+i*0.01); % each column of B contains "shifted" sin
end
bar3(B); % plot such as each "shifted" sin will have different color
rr=1:size(B,1); % numbers to label different "shifted" sin in legend
l=strtrim(cellstr(num2str(rr'))') % converting numerical labels to strings accepted by "label"
legend(l);

enter image description here

如何仅为选定的配置文件显示图例条目,例如1号,25号和最后一天?

问题类似于: How to show legend for only a specific subset of curves in the plotting? 但我不知道如何获得bar3的数字句柄,如答案所示。或者:是否存在更优雅的解决方案?

1 个答案:

答案 0 :(得分:1)

你得到了句柄:

h = bar3(B); % plot such as each "shifted" sin will have different color

然后,您只能显示所选配置文件的图例:

legend(h([1 25 end]), l{[1 25 end]})