How to animate scatter colorbar plot?

5 vues (au cours des 30 derniers jours)
Sara
Sara le 11 Juin 2017
Commenté : Sara le 15 Juin 2017
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 commentaires
KSSV
KSSV le 12 Juin 2017
Animate scatter plot, huumh..you want to add point by point and animate?
Sara
Sara le 15 Juin 2017
Yes! I would like it to animate by datetime, but keep my colorbar for each month.

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 12 Juin 2017
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

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by