1

Consider the following code:

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

How to display legend entries only for selected profiles e.g. 1st, 25th and last?

Question is similar to: How to show legend for only a specific subset of curves in the plotting? But I do not know how to get the figure handles for bar3 as suggested in the answer. Alternatively: does more elegant solution exist?

4

1 回答 1

1

You get the handles with:

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

Then you can display the legend for selected profiles only:

legend(h([1 25 end]), l{[1 25 end]})
于 2013-11-10T15:28:29.720 回答