How to animate scatter colorbar plot?

조회 수: 7 (최근 30일)
Sara
Sara 2017년 6월 11일
댓글: Sara 2017년 6월 15일
I have my original scatterplot with a colorbar that works really great to distinguish different months based on color of the dots. I would like to animate it in some way.
%%original:
figure(21)
hold on, box on, grid on;
scatter(Q,Ca_est,110,dates_asnum,'o','filled');
ylabel('Estimated Ca [ug/L]');
xlabel('Q [m^3/sec]');
c = colorbar;
datetick(c,'y');
I could not figure out how to properly animate a scatterplot with a colorbar. These are my attempts:
%%Attempt 1 plots only a static picture of my original plot:
figure(22)
hold on, box on, grid on;
scatter(Q,Ca_est,110,dates_asnum,'o','filled');
ylabel('Estimated Ca [ug/L]');
xlabel('Q [m^3/sec]');
c = colorbar;
datetick(c,'y');
F = getframe(gcf);
movie(F);
%%Attempt 2, simply doesn't do anything:
figure(23)
hold on, box on, grid on;
fig = scatter(Q,Ca_est,110,dates_asnum,'o','filled');
c = colorbar;
datetick(c,'y');
M(fig)=getframe;
%%Attempt 3, using comet3 plot: This comet plot works really well as a moving line with a single color, but I would really prefer animated dots colored by month.I have tried adding a colorbar to the comet plot itself, but could not accomplish this.
%%comet line plot, no color:
figure(24)
hold on, box on, grid on;
comet3(Q,Ca_est,dates_asnum);
Any insight is appreciated. Thank you!
  댓글 수: 2
KSSV
KSSV 2017년 6월 12일
Animate scatter plot, huumh..you want to add point by point and animate?
Sara
Sara 2017년 6월 15일
Yes! I would like it to animate by datetime, but keep my colorbar for each month.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2017년 6월 12일
clc; clear all ;
N = 100 ;
filename = 'test.gif';
data = rand(N,2) ;
figure(1)
axis([min(data(:,1)) max(data(:,1)) min(data(:,2)) max(data(:,2))])
hold on
for i = 1:N
scatter(data(i,1),data(i,2)) ;
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by