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!