How to plot a position heatmap inside a circle?
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (1)
Bruno Luong
el 9 de Sept. de 2019
Editada: Bruno Luong
el 9 de Sept. de 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 comentarios
Neuropragmatist
el 9 de Sept. de 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
el 9 de Sept. de 2019
Yes, it's purely graphical.
The boundary is clean and not have pixel stair artefact.

Manal Shakeel
el 9 de Sept. de 2019
Categorías
Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


