COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Creating a legend for sets of data points

• Email
• Follow

Trying to create a single legend for a graph with 8 data points corresponding to a set of data and 12 points for another set (trying to create a legend w/ 2 entries..1 for each set).

figure(1)
for i=1:12
hold on
p5=plot(sw3(1,i).delovx,sw3(1,i).BLgrowth,'.g');
end

for i=13:20
p10=plot(sw3(1,i).delovx,sw3(1,i).BLgrowth,'.b');
end

xlabel('\delta_{95}/x')
%ylabel('\phiRe_x^\alpha')
set(gca,'Color','w','XColor',[0.8 1 0.7],'YColor',[0.8 1 0.7])

How do I create a legend w/ entries for the data in p5 and p10??

Much appreciated,
-Jeff

 0

See related articles to this posting

On 29/08/10 4:23 PM, Jeff Martin wrote:
> Trying to create a single legend for a graph with 8 data points
> corresponding to a set of data and 12 points for another set (trying to
> create a legend w/ 2 entries..1 for each set).
>
> figure(1)
> for i=1:12
> hold on
> p5=plot(sw3(1,i).delovx,sw3(1,i).BLgrowth,'.g');
> end
>
> for i=13:20
> p10=plot(sw3(1,i).delovx,sw3(1,i).BLgrowth,'.b');
> end
>
> xlabel('\delta_{95}/x')
> %ylabel('\phiRe_x^\alpha')
> set(gca,'Color','w','XColor',[0.8 1 0.7],'YColor',[0.8 1 0.7])
>
> How do I create a legend w/ entries for the data in p5 and p10??

I suggest that instead of using plot to draw one point at a time, that
you gather the coordinates together and use scatter(). Then you can
legend() against the handles returned by scatter()

x = [sw3(1,1:20).delovx];
y = [sw3(1,1:20).BLgrowth];
p5 = scatter(x(1:12),y(1:12),'g');
hold on
p10 = scatter(x(13:20),y(13:20),'b');
xlabel(....)
ylabel(....)
legend(p5,'betty')
legend(p10,'veronica')
set(....)

 0

On Aug 30, 9:31=A0am, Walter Roberson <rober...@hushmail.com> wrote:
> On 29/08/10 4:23 PM, Jeff Martin wrote:
>
>
>
> > Trying to create a single legend for a graph with 8 data points
> > corresponding to a set of data and 12 points for another set (trying to
> > create a legend w/ 2 entries..1 for each set).
>
> > figure(1)
> > for i=3D1:12
> > hold on
> > p5=3Dplot(sw3(1,i).delovx,sw3(1,i).BLgrowth,'.g');
> > end
>
> > for i=3D13:20
> > p10=3Dplot(sw3(1,i).delovx,sw3(1,i).BLgrowth,'.b');
> > end
>
> > xlabel('\delta_{95}/x')
> > %ylabel('\phiRe_x^\alpha')
> > set(gca,'Color','w','XColor',[0.8 1 0.7],'YColor',[0.8 1 0.7])
>
> > How do I create a legend w/ entries for the data in p5 and p10??
>
> I suggest that instead of using plot to draw one point at a time, that
> you gather the coordinates together and use scatter(). Then you can
> legend() against the handles returned by scatter()
>
> x =3D [sw3(1,1:20).delovx];
> y =3D [sw3(1,1:20).BLgrowth];
> p5 =3D scatter(x(1:12),y(1:12),'g');
> hold on
> p10 =3D scatter(x(13:20),y(13:20),'b');
> xlabel(....)
> ylabel(....)
> legend(p5,'betty')
> legend(p10,'veronica')
> set(....)

Interesting, Walter.............
I would do it this way:
legend([p5 p10],'betty','Veronica',...
'Location','SouthOutside',...
'Orientation','Horizontal')

 0