Construct a 'Bubble Plot' from a matrix
21 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I want to generate a bubble plot of a matrix. Such plots are possibe to make in 'R Studio'. I have attached an example image of the desired plot.
Is there a way to do so in MATLAB?
Thanks in advance.
0 件のコメント
採用された回答
Adam Danz
2021 年 6 月 12 日
編集済み: Adam Danz
2021 年 6 月 14 日
> I want to have a sequence of colors corresponding to the the size of circles.
Assuming an n-by-m matrix r should be plotted such that point r(i,j) should appear at x=i, y=j, use meshgrid to create x and y coordinates and then set x, y, and r to bubbleplot as vectors.
The size of the bubbles is defined by |r|and the colors are based r. That way the size of the bubble shows the strength of the correlation and the color shows the direction. That could be switched around, of course.
% Create correlation matrix r
rng default % for reproducibility
r = rand(5)*2-1;
r(logical(eye(5))) = 1
% Create x and y coordinates and bubblechart
[x,y] = meshgrid(1:size(r,1), 1:size(r,2));
bubblechart(x(:),y(:),abs(r(:)),r(:))
% Cosmetics
colormap('jet')
grid on
set(gca,'xtick', 1:size(r,2), ...
'ytick', 1:size(r,1), ...
'YDir', 'Reverse'); % typically corr matrices use flipped y axes
xlabel('x index')
ylabel('y index')
cb = colorbar;
ylabel(cb, 'Correlation')
caxis([-1,1])
5 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!