Colour coding based on the number of data points in each grid?

2 ビュー (過去 30 日間)
Andi
Andi 2022 年 6 月 4 日
回答済み: Voss 2022 年 6 月 4 日
Hi everyone,
I have created a grid map and place data points in different bins based on its x, y co-ordinates. I want to allot a red color for bins with less than 100 data points and blue color for bins with more than 100 data points.
May someone suggets me how can, I fix this.
Here is my script (if someone need data please let me know)
Thank you!
x = -130.05:0.01:-129.95;
y = 45.90:0.01:46.00;
n = length(x ) ;
m = length(y ) ;
[X,Y] = meshgrid(x,y ) ;
x = axil_long ; y = axil_lat ; z = time_axil(:,1) ;
plot(X,Y,'r',X',Y','r ')
hold on
for i = 1:m-1
for j = 1:n-1
P = [X(i,j) Y(i,j ) ;
X(i,j+1) Y(i,j+1 ) ;
X(i+1,j+1) Y(i+1,j+1 ) ;
X(i+1,j) Y(i+1,j )] ;
idx = inpolygon(x,y,P(:,1),P(:,2 )) ;
iwant = [ z(idx )] ;
plot(x(idx),y(idx ),'.', color='blue') % this line is tricky, may be we need some changes here
zStore{i,j} = z(idx);
end
end
axis([-130.05 -129.95 45.90 46.00])
Here, is my grid map.

採用された回答

Voss
Voss 2022 年 6 月 4 日
You can use nnz to give you the number of points in each bin. Since you already have a logical index idx that tells you whether each point is within the current bin, then the number of points in that bin is nnz(idx). Check if nnz(idx) is greater than or equal to 100 (or greater than 100 if you like - depending on how you want the to color the points when there are exactly 100 points in the bin) or not, and color them blue or red accordingly.
Here it is with some random data:
axil_long = -130+0.02*randn(9000,1);
axil_lat = 45.95+0.02*randn(9000,1);
x = -130.05:0.01:-129.95;
y = 45.90:0.01:46.00;
n = length(x ) ;
m = length(y ) ;
[X,Y] = meshgrid(x,y ) ;
x = axil_long ; y = axil_lat ; % z = time_axil(:,1) ;
plot(X,Y,'r',X',Y','r ')
hold on
for i = 1:m-1
for j = 1:n-1
P = [X(i,j) Y(i,j ) ;
X(i,j+1) Y(i,j+1 ) ;
X(i+1,j+1) Y(i+1,j+1 ) ;
X(i+1,j) Y(i+1,j )] ;
idx = inpolygon(x,y,P(:,1),P(:,2 )) ;
% iwant = [ z(idx )] ;
if nnz(idx) >= 100
my_color = 'blue';
else
my_color = 'red';
end
plot(x(idx),y(idx ),'.', color=my_color)
% zStore{i,j} = z(idx);
end
end
axis([-130.05 -129.95 45.90 46.00])

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by