Help with TGraphPolar

Hi,

I tried using TGraphPolar for some graphing, but seemed to get unexpected result. Here is the macro file (extracted from a larger program):

[code]{
gROOT->Reset();
TCanvas * canvas = new TCanvas(“Pol”,“tet”,600,600);

TGraphPolar* g = new TGraphPolar();

g->SetPoint(0,90.6692,38.2203);
g->SetPoint(1,224.396,43.6181);
g->SetPoint(2,267.829,42.6201);

canvas->SetBorderSize(0);
canvas->SetFrameFillColor(0);

g->SetFillColor(1);


g->SetMarkerColor(3);
g->SetMarkerStyle(20);
g->SetMarkerSize(1);
	
g->Draw("AOPE");
canvas->Update();

// set the axis division; has to be done after Draw() and Update()
g->GetPolargram()->SetNdivRadial(105);
g->GetPolargram()->SetToDegree();
g->GetPolargram()->SetNdivPolar(104);


canvas->Update();

}
[/code]

And the output is attached. There are six points instead of three, and the smaller points are the one that I’m expecting; the green, larger one are the one that are recognized by the graph (since they responded to the SetMarkerColor and SetMarkerSize calls), but I don’t know where they come from.

I tried converting to radian and also tried messing with the GetPolargram()->SetToDegree() call in combination of putting the points in terms of either raidans or degrees(eventually I want to see degrees on the axis, not radians).

Any ideas as to what I did wrong? I did not find much information on TGraphPolar on the root reference pages, so I might have assumpted something wrong when finding out how to do things from TGraphErrors…

Many thanks.


I do not see the green points. I will check and let you know.

The following macro gives the attached plot and it seems ok:

{
   gROOT->Reset();
   TCanvas * canvas = new TCanvas("Pol","tet",600,600);
   TGraphPolar* g = new TGraphPolar();
   g->SetPoint(0,90.6692,38.2203);
   g->SetPoint(1,224.396,43.6181);
   g->SetPoint(2,267.829,42.6201);
   g->SetMarkerColor(3);
   g->SetMarkerStyle(20);
   g->SetMarkerSize(1);
   g->SetLineColor(4);
   g->Draw("ALP");
   canvas->Update();
   g->GetPolargram()->SetToDegree();
}

Still the documentation of TPolarGraph is very poor. I am working on that. Also I found a problem when the graph is drawn with markers. Sometimes the points are clipped wrongly. The line drawing is fine. I am working on that too.


The markers’ clipping problem is fixed in the SVN trunk.

Thanks for the help. I seem to get it to work as expected by changing drawing option and giving theta in radians. But a potential bug: if I draw with option “APOE” without setting the error, there are extra points on the graph (really small black points) that are not recognized by root (does not respond to the change in marker size, etc.).

And wishlist for TGraphPolar: I’d like to draw the angle clockwise - I can do it now by subtracting the angle from 2*pi, but I can’t change the labels to label clockwise; and I’d like to be able to specify where the pole (i.e. theta = 0) is, e.g. starting from the top, etc.

I will look at the problem you mentioned about these extra markers. I found some few other weird things needing fixes.

The angles clockwise ?.. That’s very unusual … why do you need that sort of thing ?

It is certainly not the mathematical convention :wink: but I’m drawing with an angle system that goes like: 0 degree = north, 90 degree = east, etc., and with counterclockwise drawing the orientation is confusing. That’s why also I want to rotate the graph so that the pole is in there the north usually is. But I figure I can manipulate the angle; the only problem is the label on the axis, so I make them white so that they won’t confuse people.

You can define your labels thanks to:

TGraphPolargram::SetPolarLabel()

(See help)

[quote=“couet”]You can define your labels thanks to:

TGraphPolargram::SetPolarLabel()

(See help)[/quote]

Wow, thank you for the pointer to that function! Now the plot is perfect - I only need to do 360-angle_in_degree+90 to get what I want.

TGrapPolar is a TGraphErrors and TGraphErrors allocates the Errors arrays even if they have not been set (they are 0). My guess is that the points you see appear because of that. But why do you put the option “E” the the errors are not defined ? it is it not possible to just put “OP” ?

[quote=“couet”][quote]
if I draw with option “APOE” without setting the error, there are extra points on the graph (really small black points) that are not recognized by root (does not respond to the change in marker size, etc.).
[/quote]

TGrapPolar is a TGraphErrors and TGraphErrors allocates the Errors arrays even if they have not been set (they are 0). My guess is that the points you see appear because of that. But why do you put the option “E” the the errors are not defined ? it is it not possible to just put “OP” ?[/quote]

It is of course possible to put just “OP” but since this code comes from a larger GUI program, it takes some extra checking to determine whether the user has specified the error or not - and I was kind of lazy :wink:. But now I fixed the error part, and the graph seems to work fine - although I think I still expect that if errors are not set, they are assumed to be zero.

On another note, where (if there exist) can I find some code snippet for drawing with markers on polar coordinate? My markers does not seem to show up after Draw(), and I need to set the individual markers’ size and color.

Thanks

Ok I will try to improve this (error = 0 && E option).

The transformation from polar to cartesian is done in TGraphPainter::PaintGraphPolar (in the latest SVN trunk).

[quote=“couet”]
The transformation from polar to cartesian is done in TGraphPainter::PaintGraphPolar (in the latest SVN trunk).[/quote]

I’m confused by this: should the coordinate of the marker be in polar coordinate, cartesian, or the canvas coordinate? If in polar coordinate, do I need to draw a TPolarGraph first, and how does thte TMarker “knows” about what coordinate when it Draw()?

it should be in canvas coordinate.

I fixed the dots problem in my private version. I will put it soon in the SVN trunk.

My graph is working now; thanks for the help!