How to create animated scatter plot that plots all the points one by one?
104 ビュー (過去 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]);
0 件のコメント
採用された回答
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
2022 年 9 月 15 日
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
2022 年 9 月 15 日
https://www.mathworks.com/matlabcentral/answers/512627-how-to-map-a-vector-to-a-colourmap
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!