How to animate scatter colorbar plot?
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!