1
votes

I have a strange problem that the plot overlaps in the graph, but not in the image in the same axis.

I am sure I didn't leave hold on somewhere or else it will overlap in the image itself as well.

EDIT : I want to get rid of the blue overlapped lines, I only want one blue line to be present in that pic.

Here is a sample :

(NOTE : The black image is a RGB image but I didn't plot that atm, so it IS meant to be a transition from black to white on the graph. )

alt text http://img541.imageshack.us/img541/3212/parabolaaaaa.png

Some part of the code :

   for K=1:23

    hold on
    I = fig.img.(['p' num2str(K)]);
    bw=(I);
    imshow(bw)

    ss = bwlabel(bw);
    s = regionprops(ss,'centroid');


    centroids{K} = cat(1,s.Centroid);
    hold(imgca,'on')
    plot(imgca,centroids{K}(:,1), centroids{K}(:,2), 'r*'); hold on;
    x=centroids{K}(:,1);
    y=centroids{K}(:,2);
    points=plot(x,y,'go',x,y,'rx');

    hold on
    axis on
    axis fill
    ccentroids = cat(1,centroids{:});
    C1=ccentroids(:,1);
    C2=ccentroids(:,2);
    set(points,'XData',C1,'YData',C2);

    .
    .  
    .

    p= polyfit(x2,y2,2)
    parabola_x = linspace(-250,640,500);
    parabola_polyval = polyval(p,parabola_x);
    plot(parabola_x,parabola_polyval,'b-');
    .
    .  
    .
    end

Any ideas?

1
In what order did you call your plots?Doresoom
@ZaZu - can you post some example code which produces this ?Rook
@ZaZu - Did you plot the lines, then the image, then the points? If your image already had the single blue line on it, then this would explain why the rest of the lines disappear behind it. Try placing the image on the axis, then plotting everything else. That's my best guess.Doresoom
Oh no no I want to get RID of the over lapped lines, I just want one line there ( that line moves after every point), as it moves it overlaps the one before it .. I dont want thatNLed
I don't understand where this blue line (and other blue lines) come from? You probably need to show more of your code.yuk

1 Answers

2
votes

The reason you have multiple blue lines is because you plot one for every pass through your loop with the line:

plot(parabola_x,parabola_polyval,'b-');

In fact, you are plotting everything (the images, points, and lines) over and over again in your loop without clearing the old ones.

You should instead initialize plot objects outside of your for loop and use the SET command to update them within the loop, instead of just replotting them. I gave one example of this in this answer to a question you previously asked where I discuss using the handles to plot objects to modify them. For the sample code you give here, you could do something like this:

hImage = imshow(bw(fig.img.p1));  %# Initialize the image
hold on;                          %# Add to the existing plot
hStar = plot(nan,nan,'r*');       %# Initialize the red star
hPoints = plot(nan,nan,'go',...   %# Initialize the other points
               nan,nan,'rx');
hLine = plot(nan,nan,'b-');       %# Initialize the blue line

for K = 1:23

  I = fig.img.(['p' num2str(K)]);
  bw = (I);
  set(hImage,'CData',bw);  %# Update the image

  ss = bwlabel(bw);
  s = regionprops(ss,'centroid');
  centroids{K} = cat(1,s.Centroid);
  set(hStar,'XData',centroids{K}(:,1),...  %# Update the red star
            'YData',centroids{K}(:,2));
  ccentroids = cat(1,centroids{:});
  C1 = ccentroids(:,1);
  C2 = ccentroids(:,2);
  set(hPoints,'XData',C1,'YData',C2);  %# Update the other points

  ...

  p = polyfit(x2,y2,2);
  parabola_x = linspace(-250,640,500);
  parabola_polyval = polyval(p,parabola_x);
  set(hLine,'XData',parabola_x,...      %# Update the blue line
            'YData',parabola_polyval);

  ...

end