필터 지우기
필터 지우기

retrieve legend icon property from existing legend

조회 수: 9 (최근 30일)
Fabian
Fabian 2015년 5월 19일
댓글: Fabian 2015년 6월 18일
hi all,
in the documentation to legend (R2014b) it says
[h,icons,plots,str] = legend(___) %additionally returns the objects used to create the legend icons, the objects plotted in the graph, and an array of text strings.
for a new legend the icons object can be changed like
icon(i).MarkerSize=25;
if you know wich i you have to refer to. i want to alter the appearance of legend markers in an existing figure that i saved in a fig file. i do not want to plot it all anew. is there any more elegant way to retrieve an existing icons object than this one:
l=findall(gcf,'tag','legend');
[lh,ic,~,~]=legend(l.String,'Interpreter',l.Interpreter,'FontSize',l.FontSize,...
'TextColor',l.TextColor,'Units',l.Units,'UserData',l.UserData,'FontWeight',l.FontWeight,...
'Position',l.Position,'Color',l.Color,'Box',l.Box,'FontName',l.FontName,...
'Location',l.Location,'LineWidth',l.LineWidth); % transfer all properties from existing legend
delete(l)
i=findall(ic,'Type','Line'); % reduce to lines
for m=1:length(i) % change properties
i(m).MarkerSize=25;
end
thanks, Fabian
  댓글 수: 2
Fabian
Fabian 2015년 5월 20일
i dont know why this did not work in yesterday's Matlab session (i tried that, sure), but the solution worked today and is as simple as can be:
[lh,ic]=legend;
with ic the legend icon object where one can then find the line objects as posted above
Fabian
Fabian 2015년 6월 18일
well using my function again on a plotyy-generated graph i was unable to return the icons in any way.
legend(axis) % with axis handle to where the legend is set
the lh was returned, but ic was empty...

댓글을 달려면 로그인하십시오.

답변 (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