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