Keeping plot legend in foreground
이전 댓글 표시
When I add a line object to my plot, the legend is for some reason pushed into the background behind the plot axis, where it is hidden. Why does this happen and how do I bring it into the foreground again?
댓글 수: 1
Azzi Abdelmalek
2012년 10월 19일
Can you post your code?
채택된 답변
추가 답변 (2개)
Andrianna Ayiotis
2018년 12월 12일
편집: Andrianna Ayiotis
2018년 12월 12일
1 개 추천
I had a similar problem recently but with my legend hiding behind one of my 6 subplots. When I used
set(gcf,'children',flipud(get(gcf,'children')))
my legend would then hide behind other the other subplots if I dragged it up there.
The MATLAB documentation says that the 'children' property of gcf cannot be used to add or delete graphical arrays in the group, only to reorder them. Here is a general way to make sure the legend is in front of all the other plots but be careful with this method if you have overlapping subplots that need to be stacked in a certain order.
ax = get(gcf,'children');
ind = find(isgraphics(ax,'Legend'));
set(gcf,'children',ax([ind:end,1:ind-1]))
Torben Knudsen
2022년 9월 28일
0 개 추천
I have solved a similar problem with
set(lh,'Color','white');
where lh is the legend handle
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!