The following code is replacing the first legend (hfar) by the second one (hpod), despite using another handle:
hfar= legend(far,legfar, 'Location', [...]);
hpod= legend(pod,legpod, 'Location', [...]);
Thank you
Daniel
-naor
"Daniel Walker " <dwamail...@gmx.ch> wrote in message <f8cgms$335$1...@fred.mathworks.com>...
Is it also possible to write all in the same legend box?
yes
>> x= 0:0.01:2*pi;
>> y = sin(x);
>> plot(x, y, 'k:', pi/2, 1, 'or', pi, 0, 'xg')
>> legend('sin', 'peak', 'zero')
~Adam
Now, how would I do to produced to different legend boxes,
one for the function plot and one for the points.
Sorry to be so insistent.
thanj^k you inadvance
Thomas
To create two legends, you can create two axes and
associate each with the appropriate data. E.g.
x= 0:0.01:2*pi;
y = sin(x);
hl1 = line(x, y,'Color','k','LineStyle','--');
ax1 = gca;
set(ax1,'xlim',[0, 7],'ylim',[-1,
1],'XColor','k','YColor','k');
legend_handle1 = legend(' sin');
ax2 = axes('Position',get(ax1,'Position'),...
'xlim',[0, 7],'ylim',[-1,1],...
'Visible','off','Color','none');
hl2 = line(pi/2, 1,'Color','r','Marker', 'o','Parent',ax2);
hl3 = line(pi, 0,'Color','g','Marker', 'x','Parent',ax2);
legend_handle2 = legend('peak', 'zero');
set(legend_handle2, 'Color', 'none');
An issue with this is that the second legend will be place
on top of the first. You'll have to grab it with your
mouse and move it where you like.
Of course, the approach Adam suggested is much simpler and
preferred when two axes are not needed.
I came across this two-axis approach because I needed two
y-axes with multiple data records per axis. As I
understand, plotyy allows only one data record per axis.
A question I have is "Is it possible and if so, how might
I create just one box around both legends?" I could set
the show box property to off for the individual legends
and then draw one box around both by hand, but I'd like to
find an automated approach if possible.
Tony
> To create two legends, you can create two axes and
> associate each with the appropriate data. E.g.
Thanks, this code works nicely =)
> An issue with this is that the second legend will be place
> on top of the first. You'll have to grab it with your
> mouse and move it where you like.
This is easly solved by setting the Location property, e.g.
legend_handle2 = legend('peak', 'zero','Location','SouthEast');
//Johan
If I created another legend, it will overwrite the existing legend. From the previous discussion, you add the position. My plot is on log and there are a lots of data than I mentioned as above and I don't know how to set the position of the axes.
I want to split the legend (a to d) in one box and (e-h) into another box. How can I program it?
Others who know the answer, please kindly contribute your opinion. Thanks in advance.
-Sarrah
try this:
x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
x2 = [1:.2:20];
y2 = x2.^2./x2.^3;
hl1 = line(x1,y1,'Color','r');
ax1 = gca;
set(ax1,'XColor','r','YColor','r')
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
hl2 = line(x2,y2,'Color','k','Parent',ax2);
it works.
-ken
"sarrah " <gto_g...@yahoo.com> wrote in message <himrjj$qvn$1...@fred.mathworks.com>...
What exactly do you mean by "below". And how do you add an axes?
Nice example.
You forgot to include the 'legend' statements.
Yours,
Raj
=========
figure(1) ; clf ;
x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
x2 = [1:.2:20];
y2 = x2.^2./x2.^3;
hl1 = line(x1,y1,'Color','r');
ax1 = gca;
set(ax1,'XColor','r','YColor','r')
legend('legend1') ;
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
hl2 = line(x2,y2,'Color','k','Parent',ax2);
legend('legend2','location','SE') ;
============
"Ken " <kk...@cornell.edu> wrote in message <hoaatq$dnb$1...@fred.mathworks.com>...