How do I plot intensity of points on a scatter plot?

16 ビュー (過去 30 日間)
Rebecca Bullard
Rebecca Bullard 2016 年 8 月 28 日
コメント済み: dpb 2018 年 6 月 29 日
Hey all, I'm a beginner at this but would appreciate some help!
I have a plot of x and y coordinates and I would like to plot them to show the intensity of the points. For example if an (x,y) point occurs quite a bit then it will be dark red on the plot whereas a point that only occurs once will be light blue or something similar. I would greatly appreciate if anyone could help get me started as I haven't been able to find anything or figure it out on my own.

回答 (2 件)

dpb
dpb 2016 年 8 月 28 日
編集済み: dpb 2016 年 8 月 28 日
Nuthin' to it...try
x=randn(100,1);y=randn(100,1); % sample data
scatter(x,y,20*abs(y),y,'filled')
colormap(hsv)
See
doc scatter % for details
ADDENDUM
Oh, I just happened to reread the question; I scanned it too quickly before, it seems--the above is color/size proportional to magnitude, not frequency.
[~,bin]=histc(y,linspace(min(y),max(y),10)); % location of nth bin
scatter(x,y,20*abs(y),bin,'filled')
Above is size of marker by magnitude, color by frequency of occurrence...as always, "salt to suit"...
  2 件のコメント
Olivia Licata
Olivia Licata 2018 年 6 月 29 日
Every time I run these two lines, ([~,bin]...) no figures result. Even after deleting the lines of code, MATLAB stops running scripts and I have to restart my whole system.
dpb
dpb 2018 年 6 月 29 日
Show exactly what code these two lines are...just checked here to make sure were no typos, etc.

サインインしてコメントする。


Thorsten
Thorsten 2016 年 8 月 29 日
If the x and y values are not 100% identical, you have to set up a grid and count the number of points in each grid, using hist2
x=randn(10000,1);y=randn(10000,1); % sample data
% adapt these values according to your data
Nbins = 64;
xmin = -4; xmax = 4;
ymin = -4; ymax = 4;
H = hist3([x y], {linspace(xmin, xmax, Nbins), linspace(ymin, ymax, Nbins)});
imshow(H, [])
colormap jet

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by