필터 지우기
필터 지우기

How to create a legend with multiple colored squares?

조회 수: 7 (최근 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 CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by