Alphanumeric TGraph labels

hi,

i have a rather simple problem but no matter what i try, i don’t succeed to solve it:
i want to plot a few values taken at some points in time (point in time: x-axis, value w/ error: y-axis). as a histogram, i didn’t manage to draw the right error bars but as a TGraph the curve looks nice. However, the method

for(int i=0;i<n;i++) gr->GetXaxis()->SetBinLabel(i,date[i]);

doesn’t work! All the labels are written in the first bin! And I can’t find anything else in the ROOT documentation…
Any ideas how to fix this?

cheers,
Kati

Can you send a small macro reproducing the problem ?
Meanwhile you can have a look at:
root.cern.ch/root/html/tutorials … ls1.C.html
root.cern.ch/root/html/tutorials … ls2.C.html

Also there is an other way to define time axis. See:
root.cern.ch/drupal/content/how- … time-units

yeah i looked at both of the tutorial examples already but it doesn’t work for my case…
and the thing is that my dates have the format “mid july”, “beginning of september”, so i can’t define a proper time format for the x-axis…

Ok, so can you send me a small macro reproducing your problem ?
Thanks.

Here is the macro (the slope values are calculated earlier in the macro):

   const int nx = 8;
   const double* par1[nx] = {slope1,slope2,slope3,slope4,slope5,slope6,slope7,slope8};
   double err[nx] = {sloperr1,sloperr2,sloperr3,sloperr4,sloperr5,sloperr6,sloperr7,sloperr8};
   double num[nx] = {1,2,3,4,5,6,7,8};
   string date[nx] = {"April","End of May","End of June","Mid July","Beg of Aug","End of Sept","Beg of Oct","Beg of Oct"};
   Long64_t n = 8;
   double mean = TMath::Mean(n,par1);
   //  TH2F *h = new TH2F("h","variation of center position",nx,0.0,nx,nx,-0.0005,0.00045);
   //   TH1D *h = new TH1D("h","variation of center position",nx,1,nx);
   //   h->SetBit(TH1::kCanRebin);
   //   h->SetStats(0);
   //  double x[nx],y[nx];

   TGraphErrors* gr1 = new TGraphErrors(nx,num,par1,0,err);
   TF1 *mfunc = new TF1("mfunc","mean + [0]*x",0,8);

   //   for(int i=0;i<=nx;i++) {
     //     x[i]=i; 
     //    y[i]=par1[i];
   //     h->Fill(i,par1[i]);
     //     h->Fill(par1[i]);
     //     h->SetBinError(i,err[i]);
   //   }
//   }

   gr1->SetMarkerColor(4);
   gr1->SetMarkerStyle(21);
   gr1->Draw("ALP");
   mfunc->Draw("SAME");

You can try this:

{
   TCanvas *c1 = new TCanvas("c1","ABC",10,10,900,500);
   const Int_t n = 20;
   Int_t i;
   char *ABC[n] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T"};
   Double_t x[n], y[n];
   for (i=0;i<n;i++) {
      x[i] = i*0.1;
      y[i] = 10*sin(x[i]+0.2);
   }
   TH1F *h = new TH1F("h","test",n,x[0],x[n-1]);
   for (i=1;i<=n;i++) h->GetXaxis()->SetBinLabel(i,ABC[i-1]);
   h->SetMaximum(12);
   h->Draw();
   TGraph *gr = new TGraph(n,x,y);
   gr->Draw("CP");
}

it works, thanks a lot! :slight_smile: