Ticks on a labeled plot

Hi,

I have a TMultiGraph which I have placed a labeled axis on
however the ticks for the axis do not seem to appear I have selected the ticks option, but this did not work. The only place where the ticks appear is on the ends of the axis

thanks again for your help

Maki

1 Like

Please post the shortest possible RUNNING script explaining your problem.

Rene

Hi,
Attached is a short example

thanks for your help

Maki
example.C (1.45 KB)

I see the problem. I am looking at it. I will let you know.

When you plot a TGraph, a 1D histogram is created to draw the axis. By default this histogram has 100 bins. This histogram will also hold the alphanumeric labels you are setting. When an histogram is drawn with alphanumeric labels, tick marks are drawn for each bins. Of course when the number of bins is big enough, that’s very hard to see the interval between 2 bins and eventually the tick marks touch each other, that’s why at some point, they are not drawn anymore. You are in that case. The following macro shows a way to bypass this problem. The histogram used by the TGraph is define in the macro to have only 50 bins. Then the ticks appear.

void plot_graph() {

     TCanvas *c1 = new TCanvas("ewb", "ewb",281,93,700,500);
     c1->SetGrid();

     Int_t xpoints[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};

     Int_t ypoints[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};

     TGraph *gr1 = new TGraph(13, xpoints, ypoints);
     TH1D *h1 = new TH1D("h1","h1",50,0,14); 
     h1->SetMaximum(14);
     gr1->SetHistogram(h1);   

     std::vector<std::string> label;

     label.push_back("6.3x10^{-5}");
     label.push_back("1.0x10^{-4}");
     label.push_back("4.7x10^{-4}");
     label.push_back("0.0010");
     label.push_back("0.0027");
     label.push_back("0.0100");
     label.push_back("0.0460");
     label.push_back("0.0500");
     label.push_back("0.1000");
     label.push_back("0.3170");
     label.push_back("0.5000");
     label.push_back("0.7000");
     label.push_back("0.9000");

     Int_t i;
     for (i=1;i<=13;i++) {
       int bin = gr1->GetXaxis()->FindBin(i);
       gr1->GetXaxis()->SetBinLabel(bin,label[i-1].c_str());
     }

     gr1->SetTitle("1-Dim");
     TAxis *ax = gr1->GetXaxis();
     ax->LabelsOption("d");               
     ax->SetTitle("fraction of survivors");

     gr1->Draw("ALP");
}

Sirry my example was a little simplistic…
I am trying to do the same with a TMultiGraph
which does not have SetHistogram

so I tried instead:

TH1 *h1 = p_value_chi_squared->GetHistogram();
h1->Rebin();

but I get the following error: illegal pointer to class object h1 0x0 394
at this point in the code?

thanks

Maki

Can you send me a small macro showing what you are doing with multigraphs ?

Hi sorry for the confusion, attached is my code… and I get the following error:

illegal pointer to class object h1 0x0 394 plotting.C:26

thanks for your help

Maki
multigraph.C (2.01 KB)

A file is missing. I get:

Error in <TFile::TFile>: file p_value_cuts_1600_max_order.root does not exist

sorry I attached the wrong file
try this one…
the only difference between this and my code is that the TMultigraph is stored in a root file so I don’t have direct access to the individual TGraphs

thanks again

Maki
example.C (1.8 KB)

do:

example() {
     TCanvas *c1 = new TCanvas("ewb", "ewb",281,93,700,500);
     c1->SetGrid();
     Int_t ypoints[13] = {1,1,1,1,1,1,1,1,1,1,1,1,1};
     Int_t xpoints[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
     TGraph *gr1 = new TGraph(13, xpoints, ypoints);
     Int_t xpoints1[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
     Int_t ypoints1[13] = {2,2,2,2,2,2,2,2,2,2,2,2,2};
     TGraph *gr2 = new TGraph(13, xpoints1, ypoints1);
     TMultiGraph *mgr = new TMultiGraph("mgr", "mgr");     
     mgr->Add(gr2);
     mgr->Add(gr1);
     mgr->Draw("ALP"); 
     gPad->Update();
     TH1 *h1 = mgr->GetHistogram();
     h1->Rebin(2);
     std::vector<std::string> label;
     label.push_back("6.3x10^{-5}");
     label.push_back("1.0x10^{-4}");
     label.push_back("4.7x10^{-4}");
     label.push_back("0.0010");
     label.push_back("0.0027");
     label.push_back("0.0100");
     label.push_back("0.0460");
     label.push_back("0.0500");
     label.push_back("0.1000");
     label.push_back("0.3170");
     label.push_back("0.5000");
     label.push_back("0.7000");    
     label.push_back("0.9000"); 
     mgr->Draw("ALP");
     Int_t i;
     for (i=1;i<=13;i++) {
       mgr->GetXaxis()->LabelsOption("d");
       int bin = mgr->GetXaxis()->FindBin(i);
       mgr->GetXaxis()->SetBinLabel(bin,label[i-1].c_str());
       
     }
}