How to plot a position heatmap inside a circle?
古いコメントを表示
I have x and y coordinates of animal inside a circular arena. I am using hist3 in Matlab to plot a heatmap. I would like to visualize it inside a circle, instead of the default a square with axes (left).


What I would like is this: A circle showing the heatmap, with the white outside. This is just acircle plotted on top and its not aligned properly, because I had trouble passing the centre and axis limits.
I am using hist3 and then imagesc to plot.
Any ideas how to achieve this?
採用された回答
その他の回答 (1 件)
Bruno Luong
2019 年 9 月 9 日
編集済み: Bruno Luong
2019 年 9 月 9 日

Hide the ouside with a patch
close all
im=peaks; % your heatmap
imagesc(im)
ax = gca;
xl = xlim(ax);
yl = ylim(ax);
% build the patch
x = xl([1 2 2 1 1]);
y = xl([1 1 2 2 1]);
theta = pi+linspace(0,-2*pi).';
% center coordinates and radius of the circle
xc = mean(xl);
yc = mean(yl);
r = diff(xl)*0.3/2;
% rectangle + circle
x = [x(:); xc+r*cos(theta)];
y = [y(:); yc+r*sin(theta)];
% plot on top of the image
hold on
patch('XData',x,'YData',y,'EdgeColor','none','FaceColor','w');
axis equal
3 件のコメント
Neuropragmatist
2019 年 9 月 9 日
This is a cool way to do it. The benefit of my approach is that statistics can be gathered from the heatmap after masking (std, mean, median etc) and the logical mask can be used to cut other maps of the same size.
M.
Bruno Luong
2019 年 9 月 9 日
Yes, it's purely graphical.
The boundary is clean and not have pixel stair artefact.

Manal Shakeel
2019 年 9 月 9 日
カテゴリ
ヘルプ センター および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


