How to create a legend with multiple colored squares?

7 次查看(过去 30 天)
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.
Thanks for your help!!

采纳的回答

Arthur Roué
Arthur Roué 2020-7-22
% 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 个评论
Arthur Roué
Arthur Roué 2020-7-22
% 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')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by