Problem with ticks and labels

Hello,

I have a problem. I’m trying to set just 4 ticks on my histogram. To do that I use

SetNdivisions(4,kFALSE)

It works, but then if I want to set some labels on histogram everything is messed up. Could someone explain what is the problem and how to solve it. Here is whole code for macro (crucial are last four lines):

{
//=========Macro generated from canvas: c1/c1
//=========  (Thu Jun 11 11:12:14 2009) by ROOT version5.22/00a
   TCanvas *c1 = new TCanvas("c1", "c1",12,48,700,500);
   c1->Range(-95.00001,-0.13125,865,1.18125);
   c1->SetBorderSize(2);
   
   TH1 *h = new TH1F("SUMDIG_ndigis_Barrel","SUMDIG_ndigis_Barrel",768,1,769);
   
   TPaveStats *ptstats = new TPaveStats(0.78,0.835,0.98,0.995,"brNDC");
   ptstats->SetName("stats");
   ptstats->SetBorderSize(2);
   ptstats->SetFillColor(19);
   ptstats->SetTextAlign(12);
   TText *text = ptstats->AddText("SUMDIG_ndigis_Barrel");
   text->SetTextSize(0.0368);
   text = ptstats->AddText("Entries = 0      ");
   text = ptstats->AddText("Mean  =      0");
   text = ptstats->AddText("RMS   =      0");
   ptstats->SetOptStat(1111);
   ptstats->SetOptFit(0);
   ptstats->Draw();
   h->GetListOfFunctions()->Add(ptstats);
   ptstats->SetParent(h->GetListOfFunctions());
   h->GetXaxis()->SetTitle("Modules");
   h->GetYaxis()->SetTitle("mean ndigis per Module");
   h->Draw("");
   
   TPaveText *pt = new TPaveText(0.01,0.9390678,0.3748276,0.995,"blNDC");
   pt->SetName("title");
   pt->SetBorderSize(2);
   pt->SetFillColor(19);
   text = pt->AddText("SUMDIG_ndigis_Barrel");
   pt->Draw();
   c1->Modified();
   c1->cd();
   c1->SetSelected(c1);
   
   TAxis* axis = h->GetXaxis();
   axis->SetNdivisions(4,kFALSE);
   axis->SetBinLabel(193,"Shell");
   axis->LabelsOption("h");
}

I would appreciate any help.

Your axis is alphanumeric. You have:

axis->SetBinLabel(193,“Shell”);

In such case the number of divisions does not apply.

Is there any workaround? I want to have four ticks at specific bins labeled with some text.

Make 4 bins, you fill bin 193 therefore you will have 193 bins.

I can’t do this. I need all 768 bins, since everyone of them will contain information. What I want to do is to label first 194 bins with one label, next 194 with another and so on.

I know this can be done with TText, but I need this information to be contained in histogram since I don’t have access to canvas.

It looks like that my question is not so trivial. It’s kind of surprising that ROOT can’t do such a simple thing.

You make it more complex wanting to solve it with only one Histogram Draw().
The way to do it would be to draw the histogram without labels and ticks and redo on top the axis you want. a bit like in the transpad.C example. Or to use TText. But I gathered that’s not what you want.