# Make distribution visible in scatter plots

5 views (last 30 days)
Joel Schelander on 17 May 2021
Edited: Adam Danz on 17 May 2021
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]);

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') Also try setting BinMethod or or bin edges in histogram2.

R2019b

### Community Treasure Hunt

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

Start Hunting!
{"ft_lang_label":"__label__en","ft_lang_prob":0.7697747,"math_prob":0.89910585,"size":1263,"snap":"2022-05-2022-21","text_gpt3_token_len":372,"char_repetition_ratio":0.08260524,"word_repetition_ratio":0.019512195,"special_character_ratio":0.31195566,"punctuation_ratio":0.16376306,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9828493,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-16T22:04:37Z\",\"WARC-Record-ID\":\"<urn:uuid:355cc4da-7629-4c17-b4ea-ffb9cd72dc3d>\",\"Content-Length\":\"115188\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d45cda10-147a-4a6f-8548-1596ea8f908c>\",\"WARC-Concurrent-To\":\"<urn:uuid:bde2a5eb-644f-405f-a18b-bce5c3e695de>\",\"WARC-IP-Address\":\"23.47.146.88\",\"WARC-Target-URI\":\"https://au.mathworks.com/matlabcentral/answers/832348-make-distribution-visible-in-scatter-plots?s_tid=prof_contriblnk\",\"WARC-Payload-Digest\":\"sha1:6LPHNGY44AMAKH5NQPXQK7WU7TIGPOQU\",\"WARC-Block-Digest\":\"sha1:LC6JZDACAMGJIXF7LP322SRTKGZDJENU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662512249.16_warc_CC-MAIN-20220516204516-20220516234516-00637.warc.gz\"}"}