필터 지우기
필터 지우기

i need to divide a plot with a grid and color any grid based on the number of point in it

조회 수: 4 (최근 30일)
Hello everyone, i need your help.
I have a set of point (x,y) in a matrix nx2.
I need to create a plot that has size L1 and L2 (for example L1=1000 mm and L2=2000 mm) I need to create a grid in the plot with a step of 100 mm, and color every cell with a color based on the number of points that are inside any cell.
if a cell has so many point inside must have a certain color(for ex yellow), if the cell has not so many point must have another color(for ex blue).
thank you in advance

답변 (1개)

Michael Madelaire
Michael Madelaire 2017년 11월 14일
Hi
You should be able to use hist3 and imagesc to achieve what you seek:
data = randi(1000, 5000, 2); % Create fake data. 5000x2 with values between 1:1000 (mm)
figure;
resolution = [10, 10]; % This defines the how many bins you want 1000mm/10 = 100mm bin size
[n, q] = hist3(data, resolution);
imagesc(q{:}, n');
xlabel('length [mm]');
ylabel('length [mm]');
c = colorbar;
c.Label.String = 'Amount';
If you want custom colors you have to create you own colorbar. Else try some of the premade.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by