Borrar filtros
Borrar filtros

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

107 visualizaciones (últimos 30 días)
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]);

Respuesta aceptada

Chad Greene
Chad Greene el 27 de Jul. de 2017
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 comentarios
Joaquín González Borges
Joaquín González Borges el 15 de Sept. de 2022
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 el 15 de Sept. de 2022
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by