Re: TGraph with non-linear axis

From: Olivier Couet <Olivier.Couet_at_cern.ch>
Date: Tue, 25 Oct 2005 15:09:27 +0200 (CEST)

Here is a possible way:

Double_t Eta(Double_t x) {

   return 2.0*TMath::ATan(TMath::Exp(-1.0*x)); }

Double_t Eta1(Double_t *x, Double_t *par) {

   return Eta(x[0]);
}

void AxisTest() {

   gROOT->Reset();

   TCanvas* c1 = new TCanvas("c1", "ddd", 800, 600);
   Double_t x1 = Eta(10);
   Double_t x2 = Eta(-10);

   c1->Range(x1, 0, x2, 100);

   Double_t x[3], y[3];

   x[0] = Eta(2);
   x[1] = Eta(0);
   x[2] = Eta(-1);
   y[0] = 50;
   y[1] = 25;
   y[2] = 90;

   TGraph* graph = new TGraph(3, x, y);
   graph->Draw("L*");

   x1 = 2.0*TMath::ATan(TMath::Exp(-1.0*4.5));    x2 = 2.0*TMath::ATan(TMath::Exp(-1.0*-4.5));    TF1* f1 = new TF1("f1", Eta1, -4.5, 4.5, 1);    TGaxis *A1 = new TGaxis(x1, 10, x2, 10, "f1", 50510, "+-", 100);

   A1->SetTextColor(1);
   A1->SetLabelSize(0.02);
   A1->Draw();

}

Olivier

On Tue, 25 Oct 2005, Georgy Golovanov wrote:

>
> Hi,
>
> I can't use SetLogx() because my function is not exactly Log (see the code
> below). I defined a new function, then applied one to the TGaxis(). The axis
> looks fine on the canvas. Is there any way to apply this coordinate axis to
> the TGraph?
> Thanks in advance,
>
> - Georgy.
>
> ====================================================
> Double_t Eta(Double_t *x, Double_t *par) {
>
> return 2.0*TMath::ATan(TMath::Exp(-1.0*x[0]));
> }
>
> void AxisTest() {
>
> gROOT->Reset();
>
> TCanvas* c1 = new TCanvas("c1", "ddd", 800, 600);
> c1->Range(0, 0, 100, 100);
>
> TF1* f1 = new TF1("f1", Eta, -4.5, 4.5, 1);
>
> TGraph* graph;
>
> TGaxis *A1 = new TGaxis(5, 10, 95, 10, "f1", 50510, "+-", 100);
> A1->SetTextColor(1);
> A1->SetLabelSize(0.02);
> A1->Draw();
> }
> =====================================================
>
>
>
> On Tuesday 25 October 2005 16:04, Olivier Couet <Olivier.Couet_at_cern.ch> wrote:
> > Hi,
> >
> > Can you send a running example showing what you are doing ? why don't you
> > simply set the option SetLogx() on the canvas ?
> >
> > O.Couet
> >
> > On Tue, 25 Oct 2005, Georgy Golovanov wrote:
> > > Dear Rooters,
> > >
> > > I'm trying to draw a TGraph with non-linear X-axis (like Log
> > > scale). I've constructed a TGaxis with hand-made function and it looks
> > > fine on the canvas, but the problem is how to apply this axis to the
> > > TGraph. Is it possible?
> > > Thanks for any help,
> > >
> > > - Georgy
>
>

-- 
Org:    CERN - European Laboratory for Particle Physics.
Mail:   1211 Geneve 23 - Switzerland                     Mailbox: J25910      
E-Mail: Olivier.Couet_at_cern.ch                            Phone:   +41 22 7676522
WWW:    http://cern.ch/Olivier.Couet/                    Fax:     +41 22 7670300
Received on Tue Oct 25 2005 - 15:09:34 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET