2011-09-14 156 views
8
笛卡爾繪圖到極地直方圖

請考慮:從使用Mathematica

dalist={{21, 22}, {26, 13}, {32, 17}, {31, 11}, {30, 9}, 
     {25, 12}, {12, 16}, {18, 20}, {13, 23}, {19, 21}, 
     {14, 16}, {14, 22}, {18,22}, {10, 22}, {17, 23}} 


ScreenCenter = {20, 15} 

FrameXYs = {{4.32, 3.23}, {35.68, 26.75}} 

Graphics[{EdgeForm[Thick], White, Rectangle @@ FrameXYs, 
      Black, [email protected], Red, Disk[ScreenCenter, .5]}] 

enter image description here

我想什麼做的是計算,每一個點,它在一個座標系,如角度:

enter image description here

以上是Deisred輸出,這些都是在給定特定「角度濱」點的頻率計數。一旦我知道如何計算角度我應該能夠做到這一點。

回答

12

Mathematica爲此具有特殊的繪圖功能:ListPolarPlot。您需要在X,Y成對THETA,R對,轉換爲例說明如下:

ListPolarPlot[{ArcTan[##], EuclideanDistance[##]} & @@@ (#-ScreenCenter & /@ dalist), 
      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


UPDATE

按照意見要求,極座標直方圖可以製作如下:

maxScale = 100; 
angleDivisions = 20; 
dAng = (2 \[Pi])/angleDivisions; 

S OME測試數據:

(counts = Table[RandomInteger[{0, 100}], {ang, angleDivisions}]) // BarChart 

enter image description here

ListPolarPlot[{{0, maxScale}}, 
    PolarAxes -> True, PolarGridLines -> Automatic, 
    PolarTicks -> {"Degrees", Automatic}, 
    BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, FontSize -> 12}, 
    PlotStyle -> {None}, 
    Epilog -> {Opacity[0.7], Blue, 
       Table[ 
       [email protected] 
        { 
        {0, 0}, 
        counts[[ang + 1]] {Cos[ang dAng - dAng/2],Sin[ang dAng- dAng/2]}, 
        counts[[ang + 1]] {Cos[ang dAng + dAng/2],Sin[ang dAng+ dAng/2]} 
        }, 
       {ang, 0, angleDivisions - 1} 
       ]} 
] 

enter image description here

使用Disk扇區代替Polygon S A小的視力改善:

ListPolarPlot[{{0, maxScale}}, 
    PolarAxes -> True, PolarGridLines -> Automatic, 
    PolarTicks -> {"Degrees", Automatic}, 
    BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
    FontSize -> 12}, PlotStyle -> {None}, 
    Epilog -> {Opacity[0.7], Blue, 
       Table[ 
       Disk[{0,0},counts[[ang+1]],{ang dAng-dAng/2,ang dAng+dAng/2}],  
       {ang, 0, angleDivisions - 1} 
       ] 
       } 
] 

enter image description here

通過在Epilog中增加EdgeForm[{Black, Thickness[0.005]}]可以獲得「條」的更清晰的分離。現在標記環的數字仍然有不必要的小數點跟蹤它們。隨着更換/. Style[num_?MachineNumberQ, List[]] -> Style[num // Round, List[]]的陰謀刪除那些。最終的結果是:

enter image description here

上述情節也可以與SectorChart生成儘管該圖主要是爲了顯示出不同的數據的寬度和高度,並且不是微調爲曲線,你有固定寬度的扇區,您想要突出顯示這些方向的指示和數據計數。但可以通過使用SectorOrigin來完成。問題是我認爲一個扇區的中點爲其方向編碼,因此在一個扇區的中間有0度,我必須通過\[Pi]/angleDivisions偏移原點並在旋轉時手動指定刻度:

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

enter image description here

情節幾乎是相同的,但它是互動性更強(提示等等)。

+0

謝謝Sjoerd,有極性直方圖嗎? – 500

+0

@ 500請參閱更新 –

+0

http://t0.gstatic。com/images?q = tbn:ANd9GcTQrKELoYtiEuAElJwl6ocF60URjADZNW1KrFQ8q4npE3mxtMWP –

5

這似乎是polar coordinate system。笛卡爾到極的轉換公式in that same article

enter image description here

它返回弧度的角度。

+5

要添加到Blender的答案,請使用['ArcTan'](http://reference.wolfram.com/mathematica/ref/ArcTan.html)的兩個參數形式,因爲它會自動計算象限。 – rcollyer

+0

謝謝,將ScreenCenter = {20,15}設置爲轉換源的最佳方式是什麼? – 500

+1

用'y + ScreenCenter.y'替換所有'y',並對'x'做類似的操作。 – Blender

5

[email protected][#[[1]], #[[2]]] & /@ (# - ScreenCenter & /@ dalist) 

ScreenCenter返回的光線的角度的列表的每個點,以弧度爲單位和-pi和pi之間。

也就是說,我假設你想要圖中每個點與紅點之間的角度。

請注意使用ArcTan[x,y]而不是ArcTan[y/x],它會自動選擇適當的符號(否則您必須手工完成,如@ Blender的回答)。

+0

嘿,這真的很清楚,謝謝! – 500

+0

對不起,我瘋了。當我嘗試用你的解決方案或Sjoerd來實現時,無法在我的實際數據上繪製hi直方圖,但象限在視覺上是錯誤的。我很困惑,你能告訴我一個例子嗎?對我來說左上角,如果右下,右上,左下。 – 500

+0

@ 500我不明白你在問什麼!什麼是「執行」在這裏?你是否知道這些角度是用弧度表示的,從-pi到pi,是從x軸測量的? – acl