Scatter plot with colorbar showing density of points

68 ビュー (過去 30 日間)
omid zandi
omid zandi 2021 年 6 月 8 日
コメント済み: SALAH ALRABEEI 2021 年 6 月 8 日
Hi everyone
I want to draw scatter plot along with a colorbar showing where the points are denser. I have attached the desired output cropped images.
Any help would be greatly appreciated.
The code is also (the mat files are also attached) :
% Loading mat files.
load('OrgValues.mat')
load('ATPK_AggregatedValues.mat')
% Visualization
figure;
P1 = plot(OrgValues, ATPK_AggregatedValues, 'o','MarkerFaceColor','b');
xlim([0,max(max(ATPK_AggregatedValues, OrgValues))])
ylim([0,max(max(ATPK_AggregatedValues, OrgValues))])
hold on
P2 = plot([0,max(max(ATPK_AggregatedValues, OrgValues))],[0,max(max(ATPK_AggregatedValues, OrgValues))],'-');
hold off
XlabelText = xlabel('Orginial');
YlabelText = ylabel('Aggregated');
  2 件のコメント
KSSV
KSSV 2021 年 6 月 8 日
What data you have?
omid zandi
omid zandi 2021 年 6 月 8 日
I have attached the code and my data as mat files.
thanks in advance

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

回答 (1 件)

SALAH ALRABEEI
SALAH ALRABEEI 2021 年 6 月 8 日
You can for example measure the distance between all the coordinates, then take the inverse of minimum distance or average of al the distance between the value x(1),y(1) with all the others.
%
X = rand(1000,2);
D = pdist(X);
D = sort((squareform(D))); %
s = 1./D(2,:); % we take the miminum distance of each element except the the distance between itself at D(1,:);
s2 = 1.mean(D); % another way to use it. Depends on your data.
scatter(X(:,1),X(:,2),[],s)
  2 件のコメント
omid zandi
omid zandi 2021 年 6 月 8 日
Thanks, but would it be possible for you to convert your code according to my case as i have attached the code and mat files.
Thanks a lot
SALAH ALRABEEI
SALAH ALRABEEI 2021 年 6 月 8 日
% write this after the load line
X =[OrgValues, ATPK_AggregatedValues];
D = pdist(X);
D = sort((squareform(D))); %
s = 1./D(2,:); % we take the miminum distance of each element except the the distance between itself at D(1,:);
s2 = 1/.mean(D); % another way to use it. Depends on your data.
Then replace
P1 = plot(OrgValues, ATPK_AggregatedValues, 'o','MarkerFaceColor','b');
by this
scatter(OrgValues, ATPK_AggregatedValues,[],s,'filled');
or
scatter(OrgValues, ATPK_AggregatedValues,[],s2,'filled');

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

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by