How to create a legend with multiple colored squares?

5 ビュー (過去 30 日間)
ZimtBolten
ZimtBolten 2020 年 7 月 22 日
コメント済み: ZimtBolten 2020 年 7 月 23 日
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')
ZimtBolten
ZimtBolten 2020 年 7 月 23 日
Awesome:) Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by