Color scale of scatter plot?

조회 수: 99 (최근 30일)
Martina Bonsignore
Martina Bonsignore 2021년 11월 29일
댓글: Mathieu NOE 2021년 11월 30일
Hi! That's my problem: I have datas like this images, the red dot is a wheater station, the blue dots are lightnings, in the axies there are the lat/lon coordinates.
For each lightning I have associated a value (weight) that decrease from the station (in correspondence of this point there is 1) to the the farthest lightning ( ~0). I need that the colour of the dots changes gradually from dark blue (near the station) to light blue (the farthest lightning).
The matrix of the data is 1480x4 (first column -> datenum of the lightning, second and third columns -> coordinates, fourth column -> weight value of the lightning).
The actual code is:
scatter(longitude_lightnings,latitude_lightnings,6,'filled')
scatter(longitude_station,latitude_station,'filled')
Someone can help me? Thanks!

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 11월 29일
hello
A minor variation on the above suggestion
% dummy data
N = 100;
Xc = 5; % center X coordinate
Yc = 5; % center Y coordinate
X = randn(N,1)+Xc;
Y = randn(N,1)+Yc;
dist = sqrt((X-Xc).^2 + (Y-Yc).^2);
[weight,ind] = sort(dist,'ascend');
X = X(ind);
Y = Y(ind);
% light to dark blue colormap
n=256; % number of colors
cmap = [linspace(.9,0,n)', linspace(.9447,.447,n)', linspace(.9741,.741,n)']; % light to dark blue colormap
cmap_inverted = flip(cmap); % now dark to light blue
S = (weight-min(weight))/(max(weight)-min(weight))*(n-1)+1; % map to n colors
scatter(Xc,Yc,'r', 'filled');hold on
scatter(X,Y,[],S, 'filled');hold off
colormap(cmap_inverted)
hcb=colorbar('ver'); % colorbar handle
hcb.FontSize = 12;
hcb.Title.String = "Range";
hcb.Title.FontSize = 15;
  댓글 수: 2
Martina Bonsignore
Martina Bonsignore 2021년 11월 30일
Thanks a lot! That is perfect
Mathieu NOE
Mathieu NOE 2021년 11월 30일
My pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chunru
Chunru 2021년 11월 29일
x = randn(100, 1);
y = randn(100, 1);
cmap = parula(512);
cmap = cmap(1:360, :); % dark blue to green (360 colors)
pos_station = [0 0];
c = sqrt((x-pos_station(1)).^2 + (y-pos_station(2)).^2);
c = (c-min(c))/(max(c)-min(c))*359+1; % map to 360 colors
scatter(x,y,[],c, 'filled');
colormap(cmap)
colorbar

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by