How do I create a Polar Bivariate Histogram?

12 ビュー (過去 30 日間)
Michael
Michael 2014 年 6 月 24 日
回答済み: Frederick Zittrell 2019 年 4 月 1 日
I am trying to create a histogram in polar coordinates, but I can't use the rose command because I want the histogram to depend both on rho and theta. It was easy to create this in Cartesian coordinates because I could just use hist3 (in the Statistics Toolbox), which doesn't exist for polar.
The input coordinates are in histData which is an Nx2 matrix with the x,y coordinates of each point. I based my code off of Doug's Histogram, but have been having issues of converting it to polar.
As you can see from the pictures below (Cartesian one is correct), it has somehow flipped the distribution from center-heavy to edge-heavy. Also there's always once slice that has a substantially lower density than the others, which shouldn't happen.
[histPolth,histPolr] = cart2pol(histData(:,1),histData(:,2));
rBins = 3;
thBins = 5;
width = 5; % size of circle
thi = linspace(-pi,pi,thBins);
ri = linspace(0,width/2,rBins);
[TH,R] = meshgrid(thi,ri);
[X,Y] = pol2cart(TH,R);
thHist = interp1(thi,1:length(thi),histPolth,'nearest');
rHist = interp1(ri,1:length(ri),histPolr,'nearest');
Z = accumarray([thHist rHist],1,[thBins rBins])';
figure()
surf(X,Y,Z);
view(2); % flatten to 2-D
daspect([1 1 1]); % set aspect ratio
MATLAB 2011a (Mac)
  3 件のコメント
Michael
Michael 2014 年 7 月 3 日
Using the area normalization from the previous comment, I was able to divide the accumarray input as 1/Area where Area = r*dr*dth+dr^2*dth/2. This gave me a closer representation of the data, but still had issues in the center of the graph (where r = 0) (where it should have the highest distribution). Here's what I have so far:
Michael
Michael 2014 年 7 月 7 日
So it's an "error" in the interp1 function because the inner parts will only get rounding from the 0 - 0.5 units, which has a smaller area than the others. I had to create a RoundDown function to round a list of points down to the gridlines. This also made graphing easier since the colors are dependent on the "lower r" in the polar case.
It's fixed now.

サインインしてコメントする。

採用された回答

Michael
Michael 2014 年 8 月 5 日
Self-answered in comments.
  3 件のコメント
Anne-Laurène Panadero
Anne-Laurène Panadero 2016 年 3 月 4 日
Hi Michael and Mitchell,
I have to admit that I am in the position Mitchell was a few weeks ago and I have issues to understand what you did to make it work on the 7th of July 2014. May I ask you as well if you could to post your amended script ?
Thank you,
Anne-Laurene
Michael
Michael 2016 年 6 月 14 日
編集済み: Michael 2016 年 6 月 14 日
I ended up not using this histogram, so I did not do extensive testing. I am not even sure if what I did actually worked. However, MATLAB 2016b should natively support this function.
From the release notes : "[New feature] polarscatter and polarhistogram Functions: Create scatter and histogram plots in polar coordinates"

サインインしてコメントする。

その他の回答 (1 件)

Frederick Zittrell
Frederick Zittrell 2019 年 4 月 1 日
I wrote this function that creates a bivariate histogram from polar coordinates:
The histogram grid is a simple cartesian grid and not a radial grid, though.

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by