Arctan Binning,从绘图到直方图,技巧

发布于 2024-12-05 06:29:11 字数 2110 浏览 1 评论 0原文

基于 Sjoerd,这是关于使用 Mathematica 从笛卡尔图到极坐标直方图的出色解决方案和扩展,请考虑以下内容:

list = {{21, 16}, {16, 14}, {11, 11}, {11, 12}, 
        {13, 15}, {18, 17}, {19, 11}, {17, 16}, {16, 19}}

ScreenCenter = {20, 15}

ListPolarPlot[{ArcTan[##], EuclideanDistance[##]} & @@@ (# - ScreenCenter & /@ list), 
              PolarAxes -> True, PolarGridLines -> Automatic, Joined -> False, 
              PolarTicks -> {"Degrees", Automatic}, 
              BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
              FontSize -> 12}, PlotStyle -> {Red, PointSize -> 0.02}]

在此处输入图像描述

Module[{Countz, maxScale, angleDivisions, dAng},
        Countz = Reverse[BinCounts[Flatten@Map[ArcTan[#[[1]] - ScreenCenter[[1]], #[[2]] - 
                 ScreenCenter[[2]]] &, list, {1}], {-\[Pi], \[Pi], \[Pi]/6}]];
        maxScale = 4;
        angleDivisions = 12;
        dAng = (2 \[Pi])/angleDivisions;

SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose],
             SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"},
             PolarAxes -> True,
             PolarGridLines -> Automatic,
             PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions,i \[Degree]}, 
             {i, 0, 345, 30}], Automatic},
             ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]}, 
             BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
             FontSize -> 12}, ImageSize -> 400]]

在此处输入图像描述

如您所见,直方图显示了应有的旋转对称性。 我尝试了一切方法来解决这些问题,但没有成功。如果没有反向,那是最糟糕的。我尝试 RotateRight 但没有成功。我觉得问题出在我的 BinCount 上。 ArcTan 输出从 -Pi 到 Pi,而 Sjoerd 建议我需要从 0 到 2Pi。但我不明白该怎么做。

编辑:问题解决了。感谢 Sjoerd、Belisarius、Heike 解决方案,我能够在给定图像重心的情况下显示眼睛注视位置的直方图。

在此处输入图像描述

Based on Sjoerd, great solution and extension on From Cartesian Plot to Polar Histogram using Mathematica, please consider the Following :

list = {{21, 16}, {16, 14}, {11, 11}, {11, 12}, 
        {13, 15}, {18, 17}, {19, 11}, {17, 16}, {16, 19}}

ScreenCenter = {20, 15}

ListPolarPlot[{ArcTan[##], EuclideanDistance[##]} & @@@ (# - ScreenCenter & /@ list), 
              PolarAxes -> True, PolarGridLines -> Automatic, Joined -> False, 
              PolarTicks -> {"Degrees", Automatic}, 
              BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
              FontSize -> 12}, PlotStyle -> {Red, PointSize -> 0.02}]

enter image description here

Module[{Countz, maxScale, angleDivisions, dAng},
        Countz = Reverse[BinCounts[Flatten@Map[ArcTan[#[[1]] - ScreenCenter[[1]], #[[2]] - 
                 ScreenCenter[[2]]] &, list, {1}], {-\[Pi], \[Pi], \[Pi]/6}]];
        maxScale = 4;
        angleDivisions = 12;
        dAng = (2 \[Pi])/angleDivisions;

SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose],
             SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"},
             PolarAxes -> True,
             PolarGridLines -> Automatic,
             PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions,i \[Degree]}, 
             {i, 0, 345, 30}], Automatic},
             ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]}, 
             BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
             FontSize -> 12}, ImageSize -> 400]]

enter image description here

As you can see the histogram shows a rotational symmetry of what it should.
I tried everything to get those straight but did not succeed. Without Reverse it is worst. I tried RotateRight without success.I feel the problem is in my BinCount.
ArcTan output from -Pi to Pi whereas Sjoerd suggested I needed to go from 0 to 2Pi. But I don`t understand how to do so.

EDIT : Problem solved. Thanks to Sjoerd, Belisarius, Heike solutions, I am able to show a histogram of the eye fixations locations given the center of gravity of an image.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

惯饮孤独 2024-12-12 06:29:11

现在只是检查,但你的第一个图似乎有缺陷:

list = {{21, 16}, {16, 14}, {11, 11}, {11, 12}, {13, 15}, 
        {18, 17}, {19, 11}, {17, 16}, {16, 19}};
ScreenCenter = {20, 15};

Show[ListPlot[list, PlotStyle -> Directive[PointSize[Medium], Purple]], 
     Graphics[
              {Red, PointSize[Large], Point[ScreenCenter], 
               Circle[ScreenCenter, 10]}], 
AspectRatio -> 1, Axes -> False]

在此处输入图像描述

ListPolarPlot[{ArcTan[Sequence @@ ##], Norm[##]} &/@ (#-ScreenCenter & /@ list), 
 PolarAxes -> True, 
 PolarGridLines -> Automatic, 
 Joined -> False, 
 PolarTicks -> {"Degrees", Automatic}, 
 BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, FontSize -> 12},
 PlotStyle -> {Red, PointSize -> 0.02}]  

在此处输入图像描述

编辑

我没有遵循您的所有代码,但屏幕中心上的反射似乎解决了问题:

Module[{Countz, maxScale, angleDivisions, dAng}, 
 Countz = BinCounts[
               {ArcTan[Sequence @@ ##]} & /@ (# + ScreenCenter & /@ -list), 
           {-Pi, Pi, Pi/6}];
 maxScale = 4;
 angleDivisions = 12;
 dAng = (2 Pi)/angleDivisions;

 SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 

  SectorOrigin -> {-Pi/angleDivisions, "Counterclockwise"}, 
  PolarAxes -> True, 
  PolarGridLines -> Automatic, 
  PolarTicks -> {Table[{i \[Degree] + Pi/angleDivisions, 
                        i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
  ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]},
   BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
    FontSize -> 12}, 
   ImageSize -> 400]]

在此处输入图像描述

编辑

在这里您可能会看到我的代码中的小错位,该错位已在 Heike 中解决回答(投票!)

Show[Module[{Countz, maxScale, angleDivisions, dAng}, 
  Countz = BinCounts[{ArcTan[
        Sequence @@ ##]} & /@ (# + 
         ScreenCenter & /@ -list), {-\[Pi], \[Pi], \[Pi]/6}];
  maxScale = 4;
  angleDivisions = 12;
  dAng = (2 \[Pi])/angleDivisions;
  SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 
   SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"}, 
   PolarAxes -> True, PolarGridLines -> Automatic, 
   PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions, 
       i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
   ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], 
      Red]}, BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
     FontSize -> 12}, ImageSize -> 400]],
 ListPlot[Plus[# - ScreenCenter] & /@ list/2.5, 
  PlotMarkers -> Image[CrossMatrix[10], ImageSize -> 10]]
 ]

在此处输入图像描述

Just checking right now, but your first plot seems flawed:

list = {{21, 16}, {16, 14}, {11, 11}, {11, 12}, {13, 15}, 
        {18, 17}, {19, 11}, {17, 16}, {16, 19}};
ScreenCenter = {20, 15};

Show[ListPlot[list, PlotStyle -> Directive[PointSize[Medium], Purple]], 
     Graphics[
              {Red, PointSize[Large], Point[ScreenCenter], 
               Circle[ScreenCenter, 10]}], 
AspectRatio -> 1, Axes -> False]

enter image description here

ListPolarPlot[{ArcTan[Sequence @@ ##], Norm[##]} &/@ (#-ScreenCenter & /@ list), 
 PolarAxes -> True, 
 PolarGridLines -> Automatic, 
 Joined -> False, 
 PolarTicks -> {"Degrees", Automatic}, 
 BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, FontSize -> 12},
 PlotStyle -> {Red, PointSize -> 0.02}]  

enter image description here

Edit

I did not followed all your code, but a reflection on the Screen Center seems to fix the thing:

Module[{Countz, maxScale, angleDivisions, dAng}, 
 Countz = BinCounts[
               {ArcTan[Sequence @@ ##]} & /@ (# + ScreenCenter & /@ -list), 
           {-Pi, Pi, Pi/6}];
 maxScale = 4;
 angleDivisions = 12;
 dAng = (2 Pi)/angleDivisions;

 SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 

  SectorOrigin -> {-Pi/angleDivisions, "Counterclockwise"}, 
  PolarAxes -> True, 
  PolarGridLines -> Automatic, 
  PolarTicks -> {Table[{i \[Degree] + Pi/angleDivisions, 
                        i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
  ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]},
   BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
    FontSize -> 12}, 
   ImageSize -> 400]]

enter image description here

Edit

Here you may see the small misalignment in my code, that is solved in Heike's answer (vote for it!)

Show[Module[{Countz, maxScale, angleDivisions, dAng}, 
  Countz = BinCounts[{ArcTan[
        Sequence @@ ##]} & /@ (# + 
         ScreenCenter & /@ -list), {-\[Pi], \[Pi], \[Pi]/6}];
  maxScale = 4;
  angleDivisions = 12;
  dAng = (2 \[Pi])/angleDivisions;
  SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 
   SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"}, 
   PolarAxes -> True, PolarGridLines -> Automatic, 
   PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions, 
       i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
   ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], 
      Red]}, BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
     FontSize -> 12}, ImageSize -> 400]],
 ListPlot[Plus[# - ScreenCenter] & /@ list/2.5, 
  PlotMarkers -> Image[CrossMatrix[10], ImageSize -> 10]]
 ]

enter image description here

生死何惧 2024-12-12 06:29:11

您可以使用ChartElementFunction选项将扇区准确定位。 ChartElementFunction的第一个参数是{{anglemin,anglemax},{rmin,rmax}}。第一个扇区的界限{anglemin,anglemax} = {-pi/12,pi/12},第二个,一个{pi/12,3 pi/12},,因此,要获得正确的旋转,您可以执行

Module[{Countz, maxScale, angleDivisions, dAng},
 maxScale = 4;
 angleDivisions = 12;
 dAng = (2 \[Pi])/angleDivisions;
 Countz = BinCounts[
   Flatten@Map[ArcTan @@ (# - ScreenCenter) &, list, {1}], 
    {-Pi, Pi, dAng}];

 SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 
  SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"}, 
  PolarAxes -> True, PolarGridLines -> Automatic, 
  PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions, 
      i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
  ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]},
  BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, FontSize -> 12}, 
  ImageSize -> 400,

  ChartElementFunction -> 
   Function[{range}, Disk[{0, 0}, range[[2, 2]], - 11 Pi/12 + range[[1]]]]]]

“

You could use the ChartElementFunction option to position the sectors accurately. The first argument of ChartElementFunction is of the form {{angleMin, angleMax}, {rMin,rMax}}. The first sector has bounds {angleMin, angleMax} = {-Pi/12, Pi/12}, the second one {Pi/12, 3 Pi/12}, etc. Therefore, to get the right rotation you could do something like

Module[{Countz, maxScale, angleDivisions, dAng},
 maxScale = 4;
 angleDivisions = 12;
 dAng = (2 \[Pi])/angleDivisions;
 Countz = BinCounts[
   Flatten@Map[ArcTan @@ (# - ScreenCenter) &, list, {1}], 
    {-Pi, Pi, dAng}];

 SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 
  SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"}, 
  PolarAxes -> True, PolarGridLines -> Automatic, 
  PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions, 
      i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
  ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]},
  BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, FontSize -> 12}, 
  ImageSize -> 400,

  ChartElementFunction -> 
   Function[{range}, Disk[{0, 0}, range[[2, 2]], - 11 Pi/12 + range[[1]]]]]]

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文