Legend for a patches object
68 views (last 30 days)
Show older comments
From the Patches help page, I have made a graphic showing the FOV for a set of sensors. I have used the 'unique color' row in the face-coloring table. I included a screen grab of the section of the document. My question is, now that I have coloring for each face, I need to add a legend entry for each color. However, the patch is one graph object, or it seems like it. That is, I can only display 1 legend entry because there is only 1 patch. How can I populate the legend with all of the items I want.
1 Comment
Star Strider
on 28 Jul 2015
We don’t have your graphic or your code. This makes it extremely difficult to provide you any sort of definitive help.
Answers (2)
Kelly Kearney
on 28 Jul 2015
I usually create placeholder single-color patches to use for labeling purposes:
% A multi-faceted patch, one color per face
x = [2 5; 2 5; 8 8];
y = [4 0; 8 2; 4 0];
c = [0 1];
h = patch(x,y,c);
% Placeholder patches
unqc = unique(c);
label = cellstr(num2str(unqc'));
hold on;
for il = 1:length(unqc)
hl(il) = patch(NaN, NaN, unqc(il));
end
% Legend
legend(hl,label);
0 Comments
Nolan
on 28 Jul 2015
1 Comment
Kelly Kearney
on 28 Jul 2015
Your example doesn't quite run correctly... mismatched sizes in you x/yData vs cdata. Are you trying to assign one color per face? If so, the range of the colormap is irrelevant, as long as you set up your dummy patches using the same mapping.
See Also
Categories
Find more on Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!