How to create a legend with multiple colored squares?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ZimtBolten
el 22 de Jul. de 2020
Comentada: ZimtBolten
el 23 de Jul. de 2020
Hey,
how can I create a legend for the background of the following plot?
I would like to have a textbox with 3 colored squares (like the background) and the related category.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/335331/image.png)
Thanks for your help!!
0 comentarios
Respuesta aceptada
Arthur Roué
el 22 de Jul. de 2020
% Create an axe
hAxe = axes(...);
% Get your patches handles
hGreen = patch(hAxe, ...);
hYellow = patch(hAxe, ...);
hRed = patch(hAxe, ...);
% Add legend
legend(hAxe, [hGreen hYellow hRed], {'Green', 'Yellow', 'Red'})
5 comentarios
Arthur Roué
el 22 de Jul. de 2020
% Create an axe
hAxe = axes(..);
% Get your patches handles
hGreen = patch(hAxe, ..);
hYellow = patch(hAxe, ..);
hRed = patch(hAxe, ..);
% Get your line handle
hData = plot(hAxe, ..)
% Add legend
legend(hAxe, [hGreen hYellow hRed, hData], {'Green', 'Yellow', 'Red', 'Data'}, ...
'Location', 'northeast')
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!