How to create animated scatter plot that plots all the points one by one?

107 次查看(过去 30 天)
Hello, I am rather new to Matlab. I am trying to make a scatter plot that plots all of the points one by one like an animation instead of all at once, while maintaining the other properties (including the colormap) that I have assigned to it. The code plots points along the longitude and latitude axis, and the points are color coded according to the colormap based on the "concentration" values. Below is the code without the animation. Thank you so much.
figure;
colormap(customMap);
axes('position',[0 0 1 1]);
plot1 = scatter(lon,lat,30,concentration,'.');
xlim([lonMin lonMax]);
ylim([latMin latMax]);
set(gca,'Color','none');
set(gca,'CLim',[0, 1E-4]);

采纳的回答

Chad Greene
Chad Greene 2017-7-27
Try this. First plot the very first point by lat(1),lon(1)
figure;
colormap(customMap);
axes('position',[0 0 1 1]);
plot1 = scatter(lon(1),lat(1),30,concentration(1),'.');
xlim([lonMin lonMax]);
ylim([latMin latMax]);
set(gca,'Color','none');
set(gca,'CLim',[0, 1E-4]);
Then loop through the remaining points, changing the data each time:
for k = 2:length(lat)
plot1.XData = lon(k);
plot1.YData = lat(k);
plot1.CData = concentration(k);
% pause 2/10 second:
pause(0.2)
end
Or if you want to keep the old points as you add new ones, do this:
for k = 2:length(lat)
plot1.XData = lon(1:k);
plot1.YData = lat(1:k);
plot1.CData = concentration(1:k);
% pause 2/10 second:
pause(0.2)
end
  10 个评论
Joaquín González Borges
Hi @Pouya @Chad Greene, I would like to make something similar to this graph that you expressed but instead of a map I have three data vectors. Two that define the scatter plot and one for the colormap. I would like to know if a gif can be made where the points appear as the value of the color used to define the color map increases.
I hope you can understand me and help me, thank you very much. I leave you the simple code of the current graph that I have. Thank you so much.
figure
hold on
scatter(vF1_atm_JPTE_ine,Gen_atm_JPTE_ine,sz,GV_F1_F4_JPTE_ine,'flled')
caxis([-0.003 0.015]);
colormap(jet);
hold off
Pouya
Pouya 2022-9-15
Hi @Joaquín González Borges see if this is helpful:
https://www.mathworks.com/matlabcentral/answers/512627-how-to-map-a-vector-to-a-colourmap

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by