blanc
September 19, 2004, 6:47pm
1
Hi,
I would like to draw a few TGraph on the same plot. Up to now, to get the right range to see all of the graphes, I was drawing a TH2F histogram with min and max values in the constructor according to what I wanted:
TH2F *hpx = new TH2F(“hpx”,"",10, 850, 902, 10, 11.5, 16.5);
hpx->SetStats(kFALSE);
hpx->Draw();
TGraphErrors *bmag_g = new TGraphErrors(nb, x, y, ex, ey);
bmag_g->Draw(“PL”);
But now I would like the range of axis Y plotted (and the graph as well) in decreasing order (ie following the example above from 16.5 at the bottom to 11.5).
I tried to set the window by switching ymin and ymax :
TH2F *hpx = new TH2F(“hpx”,"",10, 850, 902, 10, 16.5 11.5);
But it doesn’t like it that much…
I tried a hpx->GetYaxis()->SetRange(16.5, 11.5);
with no more success…
Same thing with: hpx->SetAxisRange(16.5, 11.5, “Y”);
How can I do that?
Thank you very much by advance for your help!
Guillaume
Note that I use ROOT 4.00/08.
brun
September 19, 2004, 7:00pm
2
Use the class TMultiGraph designed to draw a collection of TGraph.
See example in tutorial multigraph.C
Rene
blanc
September 20, 2004, 7:34am
3
OK, thanks for the suggestion: it’s much cleaner!
Nevertheless, I still don’t succeed in inverting the Y axis :
TMultiGraph *magmg = new TMultiGraph();
magmg->Add(bmag_g);
magmg->Add(vmag_g);
magmg->Add(rmag_g);
magmg->Add(imag_g);
magmg->GetYaxis()->SetRangeUser(gPad->GetUymax(), gPad->GetUymin());
magmg->Draw(“APL”);
Gives a segmentation violation…
So how can I put the axis’bottom up?
Thanks a lot,
Guillaume
couet
September 20, 2004, 9:02am
4
Here is an example which reverse an axis (the X axis in that case)
reverseaxis ()
{
TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
Float_t px, py;
TRandom r;
for (Int_t i = 0; i < 25000; i++) {
r.Rannor(px,py);
hpxpy->Fill(px,py);
}
TCanvas *c1 = new TCanvas("c1");
hpxpy->Draw("colz");
ReverseXAxis(hpxpy);
}
ReverseXAxis (TH1 *h)
{
// Remove the current axis
h->GetXaxis()->SetLabelOffset(999);
h->GetXaxis()->SetTickLength(0);
// Redraw the new axis
gPad->Update();
TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
gPad->GetUymin(),
gPad->GetUxmin(),
gPad->GetUymin(),
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
510,"-");
newaxis->SetLabelOffset(-0.03);
newaxis->Draw();
}
But only the axis is reversed, not the data. You have to modify the data accordingly.
blanc
September 20, 2004, 10:45am
5
OK, I finally found a solution, not that elegant, but working…
The problem is that the two functions:
TMultiGraph *magmg = new TMultiGraph();
[…]
magmg->GetYaxis()->SetLabelOffset(99);
magmg->GetYaxis()->SetTickLength(0.);
make a segmentation fault with a TMultiGraph… A bug?
Finally I re-used my first implementation with a TH2F to define the window. Then, after having put y = -y in the data:
hpx->GetYaxis()->SetLabelOffset(999);
hpx->GetYaxis()->SetTickLength(0);
c1->Update();
double aymin = -gPad->GetUymin();
double aymax = -gPad->GetUymax();
TF1 *hotay1 = new TF1(“hotay1”,"-x",aymin, aymax);
TGaxis *axe1 = new TGaxis(gPad->GetUxmin(), gPad->GetUymin(),
gPad->GetUxmin(),
gPad->GetUymax(),“hotay1” ,510,"-");
axe1->SetLabelOffset(0.01);
axe1->SetTitleOffset(1);
axe1->CenterTitle();
axe1->Draw();
And it works. But well, what a sweat! Just to reverse a axis…
Anyway, many thanks for your replies… Now I can plot supernova light-curve in the astronomical way…
Guillaume