Tags: figure, hold, initialfinal, itself, kk1, legend, likesofor, loop, matlab, overplots, plot, programming, somethingfigure

plot hold on with legend

On Programmer » Matlab

2,197 words with 3 Comments; publish: Wed, 07 May 2008 18:54:00 GMT; (20046.88, « »)

Hi,

I have a figure that overplots new data on itself, in a for loop, like

so:

for BW = initial:final

% do something

figure(kk+1)

plot(something)

hold on

end

what I would like, is the figure to display the legend on each

overplot, but keep it on hold, so when new data is overplotted - added

to the figure - it is also added to the legend.

is is possible to do this?

Regards,

Phil Newman

All Comments

Leave a comment...

  • 3 Comments
    • Phil Newman wrote:

      >

      > Hi,

      > I have a figure that overplots new data on itself, in a for loop,

      > like

      > so:

      > for BW = initial:final

      > % do something

      > figure(kk+1)

      > plot(something)

      > hold on

      > end

      > what I would like, is the figure to display the legend on each

      > overplot, but keep it on hold, so when new data is overplotted -

      > added

      > to the figure - it is also added to the legend.

      > is is possible to do this?

      > Regards,

      > Phil Newman

      >

      I've never tried anything like that, but why don't you keep your plot

      data in a long string, and in each iteration just concatanate the new

      information and reset the legend?

      Alon.

      #1; Wed, 07 May 2008 18:56:00 GMT
    • Hi,

      try this :

      figure('doublebuffer','on')

      hold on

      xlim([0 1])

      ylim([0 1])

      p(1)=plot(rand(5,1),rand(5,1),'color',ra

      nd(3,1));

      legend(p(1),'1')

      pause(.3)

      for n=2:5

      p(n)=plot(rand(5,1),rand(5,1),'color',ra

      nd(3,1));

      legend off

      legend(p(1:n),num2str((1:n)'))

      pause(.3)

      end

      #2; Wed, 07 May 2008 18:57:00 GMT
    • J=E9r=F4me wrote:

      > Hi,

      > try this :

      > figure('doublebuffer','on')

      > hold on

      > xlim([0 1])

      > ylim([0 1])

      > p=3D[];

      > for n=3D1:.5:5

      > p=3D[p;plot(rand(5,1),rand(5,1),'color',

      rand(3,1))];

      > legend off

      > legend(p,strcat(num2str((1:.5:n)','%.2f'),' MHz'))

      > pause(.3)

      > end

      >=20

      > J=E9r=F4me

      Now that is perfect!!

      Thanks very much!!

      Phil

      #3; Wed, 07 May 2008 18:58:00 GMT