Matlab - how to make a custom legend
legend, matlab
Solution
The simplest way I can think of is to first plot one rectangle of each type and construct a legend for only unique rectangles. Like so:
figure;
hold on;
% unique rectangles
plot(rand(1, 10), 'b');
plot(rand(1, 10), 'g');
% the rest
plot(rand(1, 10), 'b');
plot(rand(1, 10), 'g');
% use normal legend with only as many entries as there are unique rectangles
legend('Blue', 'Green');
You will have many lines of the same color, but a legend only for unique colors.
Problem
I have the following picture : And I would like to make a legend for it. Basically, I want to make a legend for each type of rectangle. In the legend box, I want to mark each color line according to the type of body which it marks: - green line : head - yellow line : torso - purple line : right arm - cyan line : left arm - red line : left leg - blue line : right leg This is basically custom, because I have more rectangles of each type. How can I do a custom legend and attach it to the figure which draws this picture?