How can I put my plot behind the legend (GUI)

Hello everyone,
I mad a matlab GUI with 3 axes. My first axe (handles.axes1) are filled with two figures (plotyy). But if I set my legend on it, the green line ofsecond figure (plot12) is over the legend. When I Change the legends colour to black, the Problem is still the same. The second figure from plotyy still is over the legend. Can anyone help me?
The code for the plot is the following:
[AX,H1,H2]=plotyy(handles.axes1,xwert,plot11,xwert,plot12);
grid(AX(1),'on');
l1=legend([H1;H2],'Lenkwinkel [°]', 'Fzg.-Geschw. [km/h]','Fahrpedal [%]', 'Fahrprogramm', 'Drehzahl [1000 U/min]');
It Looks like this (I dont want to see the green line in the legend):

Answers (1)

jonas
jonas on 15 Aug 2018
Edited: jonas on 15 Aug 2018
if h is the handle to your legend, i.e.
h=legend('location','northeast')
then change the backgroundcolor by:
set(h,'color','none') %transparent
set(h,'color','w') %white
I think white is default so I don't understand how you end up with your plot?

6 Comments

If it still does not work, then copy paste the following into the command window and copy the output here.
get(gca,'children')
get(gcf,'children')
Thanks for your help, but it doesnt work.
I tried to Change it, but it is completely crazy. I changed the handle of my legend to 'l1'. If i use set(l1, 'color', 'None'), I can see all lines (see Picture below). But if i use set(l1, 'color','w'), i can still see the green line... I dont have any idea whta it can be...
ans =
5×1 graphics array:
Line
Line
Line (Fahrpedal [%])
Line (Fzg.-Geschw. [km/h])
Line (Lenkwinkel [°])
ans =
49×1 graphics array:
UIControl (pushbutton10)
UIControl (text36)
UIControl (text35)
UIControl (edit14)
UIControl (text33)
UIControl (edit13)
UIControl (text32)
UIControl (text31)
UIControl (text30)
UIControl (edit12)
UIControl (text27)
UIControl (edit10)
UIControl (text25)
UIControl (text23)
UIControl (text21)
UIControl (text20)
UIControl (text18)
UIControl (pushbutton8)
UIControl (edit8)
UIControl (text16)
UIControl (listbox2)
UIControl (text15)
UIControl (pushbutton5)
UIControl (pushbutton4)
UIControl (edit7)
UIControl (text11)
UIControl (edit6)
UIControl (edit5)
UIControl (text9)
UIControl (edit4)
UIControl (text8)
UIControl (text7)
UIControl (edit3)
UIControl (edit2)
UIControl (text6)
UIControl (text5)
UIControl (text4)
UIControl (pushbutton3)
UIControl (pushbutton2)
UIControl (edit1)
UIControl (text2)
UIControl (pushbutton1)
Legend (Lenkwinkel [°], Fzg.-Geschw. [km/h], Fahrpedal [%], Fahrprogramm, Drehzahl…)
Axes (Fahrsituations-Daten)
Thanks a lot, but it isnt still working... I have really no idea, what it could be...
I'm not able to reproduce this issue at all. Could you send me an mat-file/m-file where you have this issue?
There is obviously something wrong with the legend. Only 3 out of 5 lines are associated with the legend, as you can see next to their handles where the string is missing in two cases. I would guess that also the purple line would appear in front of the legend, would they intersect.
5×1 graphics array:
Line
Line
Line (Fahrpedal [%])
Line (Fzg.-Geschw. [km/h])
Line (Lenkwinkel [°])
When you create the legend, try throwing all line handles in as input, in this way:
legend([h1 h2 h3 h4 h5],'string1','string2'...)
where h1...h5 are line handles that you create when you use plot

Sign in to comment.

Products

Release

R2016b

Asked:

on 15 Aug 2018

Edited:

on 15 Aug 2018

Community Treasure Hunt

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

Start Hunting!