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

1 回表示 (過去 30 日間)
matteo scarpelli
matteo scarpelli 2017 年 11 月 14 日
回答済み: Michael Madelaire 2017 年 11 月 14 日
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 Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by