Animated X, Y scatter plot

26 views (last 30 days)
Hi,
I have three variable X, Y, Z of length 10000 points each .Z represent signal strength. I need to generate animated X,Y plot (scatter) with signal strength represented by color. In general scenerio I clould use method given in below link.
However I would like the followings:
  1. Instead of adding single point in each loop I would like to add 10 points in each loop.
  2. Change the color of all old points to 'White' in each loop iteration.
  3. Represent thenew 10 points being added in current loop by respective colors using there signal strength given in Z. Lets say Z is a number from between -1 to 1, then Z=-1 should represent start color of colormap 'jet' and Z=1 should be last color of colormap 'jet'.
How do we acheive it.
thanks
jayant

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 19 Jul 2020
Have you tried to look at scatter? That should let you do this simply like this:
for i1 = 1:10:(numpoints-10),
plot(xP(1:i1-1),yP(1:i1-1),'w.','markersize',18)
hold on
scatter(xP(i1+(0:9)),yP(i1+(0:9)),32,zP(i1+(0:9)),'filled')
axis([xMin, xMax, yMin, yMax])
caxis([zMin, zMax])
drawnow
end
HTH
  2 Comments
Jayant chouragade
Jayant chouragade on 19 Jul 2020
Thank you. This works . However I have observed that as the more points added to plot execution becomes slow. I think this is due to Plot inside a loop is keep on adding points over and over again. I have added hold off to free the points from previous iteration.
Futher I wanted to create a movie using getframe and writeVideo function as given below but getting Error:-
Error using VideoWriter/writeVideo (line 410) One or more properties of the video is invalid. Ensure 'Quality' and 'FrameRate' property of the object and the frame dimensions are within allowed range.
What may cause this error.
Time_duration=400e-3;
frame_Rate=10000;
numpoints=1249996;
Num_of_frames=Time_duration*frame_Rate;
Pts_per_frm=312 ; % =floor(numpoints/Num_of_frames);
myWriter=VideoWriter('My_animation','MPEG-4');
myWriter.FrameRate=frame_Rate;
open(myWriter);
for i1 = 1:312:(numpoints-312),
plot(xP(1:i1-1),yP(1:i1-1),'w.','markersize',18)
hold on
scatter(xP(i1+(0:312)),yP(i1+(0:312)),32,zP(i1+(0:312)),'filled')
axis([xMin, xMax, yMin, yMax])
caxis([zMin, zMax])
colorbar;
%drawnow
frames=getframe;
writeVideo(myWriter,frames);
hold off;% to free old points from previous iteration.
end
close(myWriter);
Bjorn Gustavsson
Bjorn Gustavsson on 19 Jul 2020
Sorry about that, forgot to add in a hold off at the end of the loop.
Regarding your movie-making:
1, frame_Rate=10000; - this would give you a video for 10000 frames per second, this is to high for our human visual perception. Try with something in the range of 10 - 60, depending on how much of each frame you want the audience to see.
2, (Num_of_frames should rather be the numpoints/312, than the number you set it to.)
3, Perhaps try getframe(gfc) or getframe(gca). Also if you modify the size of the figure-window during the processing things go kaboom.
More later.

Sign in to comment.

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!