Hi Christian, The labels in TAxis are not functional. We always have in mind the implementation of histograms/ntuples with strings. Their implementation requires an extension of the simple structure foreseen in TAxis. Meanwhile, you must draw the labels by hand. Here is an example in case of a 2-d histogram. Rene Brun void BinLabels() { const Int_t nx = 12; const Int_t ny = 20; char *months[nx] = {"January","February","March","April","May","June","July", "August","September","October","November","December"}; char *people[ny] = {"Jean","Pierre","Marie","Odile","Sebastien","Fons","Rene", "Nicolas","Xavier","Greg","Bjarne","Anton","Otto","Eddy","Peter","Pasha", "Philippe","Suzanne","Jeff","Valery"}; TCanvas *c1 = new TCanvas("c1","demo bin labels",10,10,800,800); c1->SetGrid(); c1->SetLeftMargin(0.15); c1->SetBottomMargin(0.15); TH2F *h = new TH2F("h","test",nx,0,nx,ny,0,ny); for (Int_t i=0;i<5000;i++) { h->Fill(gRandom->Gaus(0.5*nx,0.2*nx), gRandom->Gaus(0.5*ny,0.2*ny)); } h->SetStats(0); h->GetXaxis()->SetLabelOffset(99); h->GetYaxis()->SetLabelOffset(99); h->Draw("text"); // draw labels along X Float_t x, y; y = gPad->GetUymin() - 0.2*h->GetYaxis()->GetBinWidth(1); TText t; t.SetTextAngle(60); t.SetTextSize(0.02); t.SetTextAlign(33); for (i=0;i<nx;i++) { x = h->GetXaxis()->GetBinCenter(i+1); t.DrawText(x,y,months[i]); } // draw labels along y x = gPad->GetUxmin() - 0.1*h->GetXaxis()->GetBinWidth(1); t.SetTextAlign(32); t.SetTextAngle(0); for (i=0;i<ny;i++) { y = h->GetYaxis()->GetBinCenter(i+1); t.DrawText(x,y,people[i]); } } Christian Theis wrote: > > Hello Root Team, > > I'm currently writing some analysis package for which I need to change the > bin labels in a 2D histogram. I actually have to label them with strings, > which according to an (obviously old class description) could be done via > the SetBinLabel function. As this does not seem to be supported anymore, > can anyone point me out how to do this. > > Thanks in advance > Chris > > --------------------------------------------------------------------------- > Chris Theis > CERN/EP - European Organisation for Nuclear Research > 1211 Geneva 23, Switzerland > Phone: +41 22 767 7372 Office: 40-2B-24 > e-mail: Christian.Theis@cern.ch www: http://www.cern.ch/ctheis > --------------------------------------------------------------------------
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:36 MET