Make distribution visible in scatter plots

2 views (last 30 days)
I have two vectors, I3 and D, of the size 1000000x1. They are plotted against each other in a scatter plot (see PIplot1)
I want to know how many values I have. For example If you look to the far right of the figure. I dont know How many values are around y=50 or how many are around y=150.
I need to make the distribution visible somehow, but I do not know how to go about it.
plot(I3,D,'.','Color', [0 0.4470 0.7410]);

Accepted Answer

Adam Danz
Adam Danz on 17 May 2021
Edited: Adam Danz on 17 May 2021
You can display the 2D binned density using histogram2.
Demo: The plot on the left and right contain the same data.
x = 1:105;
ym = randn(800, numel(x)) .* linspace(2,35,numel(x)) + linspace(6,150,numel(x)) ;
xm = repmat(x,size(ym,1),1);
figure()
tiledlayout(1,2)
ax(1) = nexttile;
plot(x,ym,'b.')
grid on
axis tight
ax(2) = nexttile;
histogram2(xm,ym,'DisplayStyle','tile')
axis tight
cb = colorbar();
ylabel(cb, 'bin count')
linkaxes(ax)
Also try setting BinMethod or or bin edges in histogram2.

More Answers (0)

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!