Re: [ROOT] user defined axis labels or how to change them !

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Aug 10 2001 - 14:55:22 MEST


Hi Joe,

In attachment, a script illustrating how to add/replace labels to the axes.

Rene Brun

joe robe wrote:
> 
> Hell Rene,
> 
> what a pitty , this looks like a lot of work ! What is
> that Get and SetBinLabel methods in TAxis, was that
> never implemented ?
> 
> What is the best approach to draw my individual axis
> labels ? Calculating the positions and then use TText,
> TLabel or so or is there any way TAxis can be modified
> for that ?
> 
> Joe
> 
> --- Rene Brun <Rene.Brun@cern.ch> wrote:
> > Hi Joe,
> >
> > Graphs with gaps are not implemented in ROOT and we
> > have no plans
> > to implement this feature in the short term. This
> > has several
> > implications (lin/log scales, picking, superimposed
> > fitted functions, etc)
> >
> > The only possibility that I see is to call the basic
> > primitives
> > or use an index (what you already do if I
> > understand).
> > For the axis values, you have to draw the individual
> > axis labels one by
> > one.
> >
> > Rene Brun
> >
> > On Thu, 9 Aug 2001, joe robe wrote:
> >
> > > hello rooters,
> > >
> > > we are still working on the problem how to draw a
> > time
> > > series chart with gaps NOT DRAWN. Stocks only
> > trade in
> > > a specific time range. If I draw a time series of
> > 2
> > > days I get a gap of approx. 18 hours in my chart.
> > >
> > > I dont think there is a way to draw a chart with a
> > > TIME X axis where part of the time is not drawn.
> > >
> > > I can draw the chart correctly by changing the X
> > axis
> > > to the index, but now my X axis shows numbers
> > instead
> > > of the time.
> > >
> > > Of course I have the corresponding time values to
> > > these numbers, so is there a way to plot user
> > defined
> > > X values ?
> > >
> > > In TAxis there  is a virtual funciotn
> > get/setBinLabel
> > > which sounds like it could do what I want, but
> > nowhere
> > > I found a implementation of  this virtual
> > funcktion !
> > >
> > > Joe
> > >
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Make international calls for as low as $.04/minute
> > with Yahoo! Messenger
> > > http://phonecard.yahoo.com/
> > >
> >
> 
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/

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]);
   }
}



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:56 MET