How to properly make a circular histogram?
I have data points which are the angle and distance around a central point. I would like to make a histogram of these points so I can visualise their distribution and also perform some analyses on their density etc.
For now, I make a 2D histogram, treating the data points as if they are cartesian X,Y coordinates. I then transform the bin centers into polar coordinates and replot the data, like this:
% create data points
theta = normrnd(0,0.5,1000,1);
rad = 100.*rand(1000,1);
figure
subplot(1,3,1)
polarscatter(theta,rad,10,’k’,’filled’,’o’)
title(‘data points’)
% prepare bins
theta_bins = linspace(-pi,pi,120);
rad_bins = 0:5:100;
% ‘normal’ histogram
f = histcounts2(rad,theta,rad_bins,theta_bins);
subplot(1,3,2)
imagesc(f)
daspect([1 1 1])
title(‘histogram in cartesian coordinates’)
% transform bin coordinates
[theta,rad] = meshgrid(linspace(min(theta_bins),max(theta_bins),length(theta_bins)-1),linspace(min(rad_bins),max(rad_bins),length(rad_bins)-1));
[X,Y] = pol2cart(theta,rad);
subplot(1,3,3)
s = surf(X,Y,f);
s.EdgeColor = ‘none’;
view(0,90);
daspect([1 1 1])
axis xy
title(‘histogram in polar coordinates’)
However, the resulting histogram is not really ideal – the bins are not homogeneous because they get larger as the radius increases. This is due to the fact that I made the histogram in a cartesian reference frame.
I was wondering if there is a better way to go about this? Some sort of circular histogram with circular bands of triangular bins? Or hexagonal bins? Can anyone suggest anything?
Thanks for any help.I have data points which are the angle and distance around a central point. I would like to make a histogram of these points so I can visualise their distribution and also perform some analyses on their density etc.
For now, I make a 2D histogram, treating the data points as if they are cartesian X,Y coordinates. I then transform the bin centers into polar coordinates and replot the data, like this:
% create data points
theta = normrnd(0,0.5,1000,1);
rad = 100.*rand(1000,1);
figure
subplot(1,3,1)
polarscatter(theta,rad,10,’k’,’filled’,’o’)
title(‘data points’)
% prepare bins
theta_bins = linspace(-pi,pi,120);
rad_bins = 0:5:100;
% ‘normal’ histogram
f = histcounts2(rad,theta,rad_bins,theta_bins);
subplot(1,3,2)
imagesc(f)
daspect([1 1 1])
title(‘histogram in cartesian coordinates’)
% transform bin coordinates
[theta,rad] = meshgrid(linspace(min(theta_bins),max(theta_bins),length(theta_bins)-1),linspace(min(rad_bins),max(rad_bins),length(rad_bins)-1));
[X,Y] = pol2cart(theta,rad);
subplot(1,3,3)
s = surf(X,Y,f);
s.EdgeColor = ‘none’;
view(0,90);
daspect([1 1 1])
axis xy
title(‘histogram in polar coordinates’)
However, the resulting histogram is not really ideal – the bins are not homogeneous because they get larger as the radius increases. This is due to the fact that I made the histogram in a cartesian reference frame.
I was wondering if there is a better way to go about this? Some sort of circular histogram with circular bands of triangular bins? Or hexagonal bins? Can anyone suggest anything?
Thanks for any help. I have data points which are the angle and distance around a central point. I would like to make a histogram of these points so I can visualise their distribution and also perform some analyses on their density etc.
For now, I make a 2D histogram, treating the data points as if they are cartesian X,Y coordinates. I then transform the bin centers into polar coordinates and replot the data, like this:
% create data points
theta = normrnd(0,0.5,1000,1);
rad = 100.*rand(1000,1);
figure
subplot(1,3,1)
polarscatter(theta,rad,10,’k’,’filled’,’o’)
title(‘data points’)
% prepare bins
theta_bins = linspace(-pi,pi,120);
rad_bins = 0:5:100;
% ‘normal’ histogram
f = histcounts2(rad,theta,rad_bins,theta_bins);
subplot(1,3,2)
imagesc(f)
daspect([1 1 1])
title(‘histogram in cartesian coordinates’)
% transform bin coordinates
[theta,rad] = meshgrid(linspace(min(theta_bins),max(theta_bins),length(theta_bins)-1),linspace(min(rad_bins),max(rad_bins),length(rad_bins)-1));
[X,Y] = pol2cart(theta,rad);
subplot(1,3,3)
s = surf(X,Y,f);
s.EdgeColor = ‘none’;
view(0,90);
daspect([1 1 1])
axis xy
title(‘histogram in polar coordinates’)
However, the resulting histogram is not really ideal – the bins are not homogeneous because they get larger as the radius increases. This is due to the fact that I made the histogram in a cartesian reference frame.
I was wondering if there is a better way to go about this? Some sort of circular histogram with circular bands of triangular bins? Or hexagonal bins? Can anyone suggest anything?
Thanks for any help. circular, histogram, polar, visualisation MATLAB Answers — New Questions