Rotating the labels

Looking into TAxis methods I came to the conclusion that

should make the labels lay on their sides (rotate by 90 degrees),
since the default is “h”. However, the only visible effect is this:

Warning in TAxis::Sort: Cannot sort. No labels

Is there a way to rotate the labels on the horisontal axis of the
histogram? I think there is, b/c I’ve seen some rotated at by
an angle that was not even 90 degrees …

Test macro: (getting hold of the palette is another thing that
does not work)

[code]
void palette_problem () {

gStyle->SetPalette(1);
TH2F* corrHisto = new TH2F(“corrHisto”, “”, 3, 0.5, 3.5, 3, 0.5, 3.5);

corrHisto->SetStats(kFALSE);
corrHisto->GetXaxis()->LabelsOption(“v”);
corrHisto->GetXaxis()->SetNdivisions(3);
corrHisto->GetYaxis()->SetNdivisions(3);
corrHisto->SetMaximum(1.0);
corrHisto->SetMinimum(0.0);

corrHisto->SetBinContent(1, 1, 1.0);
corrHisto->SetBinContent(2, 2, 1.0);
corrHisto->SetBinContent(3, 3, 1.0);
corrHisto->SetBinContent(1, 2, 0.7);
corrHisto->SetBinContent(1, 3, 0.4);
corrHisto->SetBinContent(2, 3, 0.0);
corrHisto->SetBinContent(2, 1, 0.7);
corrHisto->SetBinContent(3, 1, 0.4);
corrHisto->SetBinContent(3, 2, 0.0);

corrHisto->Draw(“COLZ”);
//TPaletteAxis palette = (TPaletteAxis)corrHisto->GetListOfFunctions()->FindObject(“palette”);
//palette->SetLabelFont(42);
//palette->SetLabelSize(0.04);
return;
}[/code]

Only histograms with alphanumeric labels can be sorted/rotated.
See tutorials labels1.C, hlabels1.C, hlabels2.C
You can modify your example like shown below

void anik () { 

gStyle->SetPalette(1); 
TH2F* corrHisto = new TH2F("corrHisto", "", 3,0,0, 3,0,0); 

corrHisto->SetStats(kFALSE); 
corrHisto->GetXaxis()->SetNdivisions(3); 
corrHisto->GetYaxis()->SetNdivisions(3); 
corrHisto->SetMaximum(1.0); 
corrHisto->SetMinimum(0.0); 

corrHisto->Fill("1", "1", 1.0); 
corrHisto->Fill("2", "2", 1.0); 
corrHisto->Fill("3", "3", 1.0); 
corrHisto->Fill("1", "2", 0.7); 
corrHisto->Fill("1", "3", 0.4); 
corrHisto->Fill("2", "3", 0.0); 
corrHisto->Fill("2", "1", 0.7); 
corrHisto->Fill("3", "1", 0.4); 
corrHisto->Fill("3", "2", 0.0); 
corrHisto->GetXaxis()->LabelsOption("v"); 

corrHisto->Draw("COLZ"); 
gPad->Update();
TPaletteAxis *palette = (TPaletteAxis*)corrHisto->GetListOfFunctions()->FindObject("palette"); 
palette->SetLabelFont(42); 
palette->SetLabelSize(0.04); 
} 

Rene

I took a look at the tutorials, it looks like one would have to jump
through a few hoops before the labels get rotated. That’s kinda
sad, given the existence of the LabelsOption(“v”) method (that
refuses to work in my case)… But coming back to the example
Rene provided – it compiles and works(!), but I don’t understand
why. IMHO, corrHisto->Fill(“3”, “3”, 1.0); should not work, b/c
the first two arguments are not Int_t … Yes, I am aware of automatic
type conversion … but why would the following NOT compile/work
then?

[code]
#include <TROOT.h>
#include <TH2F.h>
#include <TString.h>
#include <TAxis.h>
#include <TStyle.h>
#include <stdio.h>

void vlabel_problem () {

gStyle->SetPalette(1);
TH2F* corrHisto = new TH2F(“corrHisto”, “”, 3,0,0, 3,0,0);

corrHisto->SetStats(kFALSE);
corrHisto->GetXaxis()->SetNdivisions(3);
corrHisto->GetYaxis()->SetNdivisions(3);
corrHisto->SetMaximum(1.0);
corrHisto->SetMinimum(0.0);

char s1[16];
char s2[16];
for (int i=0; i!=3; ++i) {
for (int j=i+1; j!=3; ++j) {

  sprintf(s1, "%d", i+1);
  sprintf(s2, "%d", j+1);
  TString a = TString(s1);
  TString b = TString(s2);
  corrHisto->SetBinContent(a.Data(), b.Data(), 0.3);
  corrHisto->SetBinContent(b.Data(), a.Data(), 0.7);
}

}

corrHisto->GetXaxis()->LabelsOption(“v”);
corrHisto->Draw(“COLZ”);
}[/code]

Ok, looking at the tutorials helped. The key is to make all
the labels char strings (that’s what the single ‘for’ loop does
in the macro below). This works:

[code]
void vlabel_problem () {

TCanvas* canvas = new TCanvas(“c”,"",0,0,500,500);
canvas->SetLeftMargin(0.1);
canvas->SetBottomMargin(0.1);
canvas->SetTopMargin(0.05);
canvas->SetRightMargin(0.05);
canvas->SetFillColor(10);
canvas->Draw();

TH2F* corrHisto = new TH2F(“corrHisto”,"", 3,0.0,3.0, 3,0,3.0);

corrHisto->SetStats(kFALSE);
corrHisto->GetXaxis()->SetNdivisions(3);
corrHisto->GetYaxis()->SetNdivisions(3);
corrHisto->GetXaxis()->CenterLabels(kTRUE);
corrHisto->GetYaxis()->CenterLabels(kTRUE);
corrHisto->SetMaximum(1.0);
corrHisto->SetMinimum(0.0);

for (int i=0; i!=3; ++i) {
for (int j=i+1; j!=3; ++j) {

  corrHisto->SetBinContent(i+1, j+1, 0.3);
  corrHisto->SetBinContent(j+1, i+1, 0.7);
}

}

char s[16];
for (int i=0; i!=3; ++i) {
sprintf(s,"%d", i);
corrHisto->GetXaxis()->SetBinLabel(i+1, s);
corrHisto->GetYaxis()->SetBinLabel(i+1, s);
}

corrHisto->GetXaxis()->LabelsOption(“v”);
corrHisto->Draw(“BOX”);
}[/code]

… which raises a question: would it not be nice for the labelOption() method in

to convert labels of the given axis to char strings automatically,
rather than complaining about not being able to sort the labels?

We are aware of this limits see:

cern.ch/couet/POW.htm

(slide number 11)