MATLAB Answers

Matt J

Keeping plot legend in foreground

Asked by Matt J
on 19 Oct 2012

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 Comment

Azzi Abdelmalek
on 19 Oct 2012

Can you post your code?

Tags

Products

No products are associated with this question.

1 Answer

Answer by Matt Fig
on 19 Oct 2012
Edited by Matt Fig
on 19 Oct 2012
 Accepted answer

I cannot reproduce this with:

plot(1:10)
legend('plot')
line([5 5],[0 10])

So I want to ask what your code looks like. If you only have the one plot axes and the legend (no uicontrols or other figure children), then this will bring the legend back:

set(gcf,'children',flipud(get(gcf,'children')))

If you have other figure children, the idea is the same, you will just have to be more careful about the rearrangement.

  0 Comments


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today