i need to divide a plot with a grid and color any grid based on the number of point in it
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Michael Madelaire
am 14 Nov. 2017
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.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!