How to plot a position heatmap inside a circle?
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (1)
Bruno Luong
il 9 Set 2019
Modificato: Bruno Luong
il 9 Set 2019

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 Commenti
Neuropragmatist
il 9 Set 2019
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
il 9 Set 2019
Yes, it's purely graphical.
The boundary is clean and not have pixel stair artefact.

Manal Shakeel
il 9 Set 2019
Categorie
Scopri di più su Data Distribution Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


