2011-09-17 22 views
7

Sulla base di Sjoerd, grande soluzione e l'estensione sul From Cartesian Plot to Polar Histogram using Mathematica, si prega di considerare quanto segue:Arctan categorizzazione, da Plot a istogramma, i trucchi

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[[email protected][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

Come puoi vedere l'istogramma mostra una simmetria rotazionale di ciò che dovrebbe. Ho provato di tutto per ottenere quelle dritte ma non ci sono riuscito. Senza Reverse è peggio. Ho provato RotateRight senza successo. Sento che il problema è nel mio BinCount. Uscita ArcTan da -Pi a Pi mentre Sjoerd mi suggeriva di passare da 0 a 2Pi. Ma non capisco come farlo.

MODIFICA: problema risolto. Grazie a Sjoerd, Belisarius, soluzioni di Heike, sono in grado di mostrare un istogramma delle posizioni degli occhi fissi dato il centro di gravità di un'immagine.

enter image description here

+0

@beliarius: Quando si utilizza 'ArcTan' nella forma' arctan [x, y] 'l'intervallo è' (-Pi, Pi) ' – Heike

+0

@belisarius, Scusa, sono così fuori di testa ora :-(Grazie per il tuo aiuto! – 500

+0

@ 500 Presta attenzione alla soluzione di Heike come sembra corrispondere meglio alle posizioni –

risposta

5

È possibile utilizzare l'opzione ChartElementFunction per posizionare con precisione i settori. Il primo argomento di ChartElementFunction ha il formato {{angleMin, angleMax}, {rMin,rMax}}. Il primo settore ha limiti {angleMin, angleMax} = {-Pi/12, Pi/12}, il secondo {Pi/12, 3 Pi/12}, ecc Pertanto, per ottenere la rotazione a destra si potrebbe fare qualcosa di simile

Module[{Countz, maxScale, angleDivisions, dAng}, 
maxScale = 4; 
angleDivisions = 12; 
dAng = (2 \[Pi])/angleDivisions; 
Countz = BinCounts[ 
    [email protected][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

+0

nel momento in cui pensavo di essere bravo, sono tornato e ho visto la tua soluzione e commenti belisarius, grazie non ho nemmeno prestato attenzione alla posizione del bar, questo è così pulito. – 500

6

Proprio controllando in questo momento, ma la prima trama sembra viziata:

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

Modifica

non ho seguito tutto il codice, ma una riflessione sul centro dello schermo sembra risolvere la cosa:

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

Modifica

Qui è possibile vedere la piccolo disallineamento nel mio codice, che è risolto nella risposta di Heike (votare per questo!)

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