Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

plotyy, legends and ylabel

12 views
Skip to first unread message

Brian Lodahl

unread,
May 24, 2002, 4:32:22 AM5/24/02
to
Hi.

When i use plotyy to plot two functions in the same plot, it is only the
first plotted function that gets a colorized legend. How do i get both
legends colorized? (the text of both of them are displayed, but i miss the
color index)

another question: With only one plot i can use ylabel('mylabel') to give a
lable on the y-axis. How do i use this with two y-axis?

sincerely,
Brian


% Best regards;Brian Lodahl ; lod...@kom.auc.dk
% http://www.kom.auc.dk/~lodahl ; RISC group 850;Room A6-118;
% RF Integrated Systems & Circuits (RISC);Aalborg University;
% Frederik Bajers Vej 7;DK-9220 Aalborg Ø;Denmark
clc;s=zeros(1,52);c=[+'a':+'z',' '];f=5;a=clock;a=fix(f*a(6));
while(1)while(1)b=clock;b=fix(f*b(6));if(b~=a)break,end,end,a=b;
str=('my name is brian and i am just another matlab hacker');
k=find(s~=str);n=length(k);if~n,break,end;x=c(ceil(27*rand(1,n)));
s(k)=x;fprintf('\r%s',s);end;fprintf('\n');clear%;clc;str


Joe Sababa

unread,
May 24, 2002, 5:51:17 AM5/24/02
to


Hi,
Note that plotyy create two axes objects on on top of the other. You can control the properties of each. First find the axes objects (before making a legend):
>>H=findobj(gcf,'type','axes');
» axes(H(2)),ylabel('Income')
» axes(H(1)),ylabel('Value')
The legend command can be applyed only to one of the axes. This is because it is a third axes object that takes values from the current axes and the objects drawn on it.


Joe
BSTEX - Equation viewer for Matlab
<http://www.geocities.com/bstex2001>

Joe Sababa

unread,
May 24, 2002, 6:31:07 AM5/24/02
to
Joe Sababa wrote:
> Hi,
> Note that plotyy create two axes objects on on top of the other. You can
> control the properties of each. First find the axes objects (before making
> a legend):
>>>H=findobj(gcf,'type','axes');
> » axes(H(2)),ylabel('Income')
> » axes(H(1)),ylabel('Value')
> The legend command can be applyed only to one of the axes. This is because
> it is a third axes object that takes values from the current axes and the
> objects drawn on it.
> The walk around is to create one legend, than copy it and change it's position and childrens' properties:
>>axes(H(1)), HL=legend('income');
>>Pos=get(HL,'position');
>>HL1=copyobj(HL,gcf);
>>set(HL1,'position',Pos-[0 0.11 0 0])
C=allchild(HL1);
» set(C(5),'color',[0 0 0.5]) % the first 4 children is for the legend frame
» set(C(6),'String','value')

Brian Lodahl

unread,
May 24, 2002, 6:46:06 AM5/24/02
to

After having to ask an older student (there goes my pride :) i found out
how to do it. The legend also works here.
But still; thanks for the advice.

sincerely,
Brian
----[snip]----
figure(1)
subplot(211),
[ax,h1,h2]=plotyy(P_in,20*log10(abs(S_11)),P_in,VSWR);
grid
xlabel('P_{in} [dBm]')
set(get(ax(1),'Ylabel'),'String','|S_{11}|')
set(get(ax(2),'Ylabel'),'String','VSWR')
set(h1,'linestyle','-')
set(h2,'linestyle','--')
legend([h1,h2],'S_{11}','VSWR',0)
---[snap]---

0 new messages