TH2 draw with col or colz option always white canvas

Hi!
I am using root-6.05.02. If I try to draw a TH2 with the colz option I just get a white canvas (with the proper X-Y axis shown in black).
For example, if I try the first example here:

{
   TCanvas *c1 = new TCanvas("c1","c1",600,400);
   TH2F *hcol1 = new TH2F("hcol1","Option COLor example ",40,-4,4,40,-20,20);
   Float_t px, py;
   for (Int_t i = 0; i < 25000; i++) {
      gRandom->Rannor(px,py);
      hcol1->Fill(px,5*py);
   }
   gStyle->SetPalette(kBird);
   hcol1->Draw("COLZ");
   return c1;
}

I just get

instead of the nice looking histogram shown there.

Any advice? - I haven’t seen any other post regarding this exact problem, although I guess I could change the palette every time I open root, as suggested to others with similar problems, which would be quite annoying :slight_smile:
Thank you!

Does the line:

gStyle->SetPalette(kBird);

triggers any error message, saying that kBird is unknown ?

Thanks for your answer.
No, no error message. And it fixes the problem…

I see someone marked this message as the solution to the problem.
But it isn’t :frowning:
I can set a palette to get a non-white plot every time I open root, yes, but my problem is that I am forced to do this every time (while in the many other systems I’ve worked on, I didn’t have to do it). And while typing gStyle->SetPalette(kBird) in every root session would have saved me having to write this post, in the long run I’ll save time if I don’t have to :slight_smile:

So I guess the question should have been then: how to I specify the default palette to not be all white, something that works in interpreted code or in compiled code, etc.
And if anyone knows: why my root setup decided to set the palette as white instead of rainbow like everyone else’s? (!?)

Thank you!

This macro:

{
   TH2F *hcol1 = new TH2F("hcol1","Option COLor example ",40,-4,4,40,-20,20);
   Float_t px, py;
   for (Int_t i = 0; i < 25000; i++) {
      gRandom->Rannor(px,py);
      hcol1->Fill(px,5*py);
   }
   gStyle->SetPalette(1);
   hcol1->Draw("COLZ");
}

should give you his image with all ROOT versions.

Does it ?

It does with the three I’ve just tried.

So… that’s fine … ? …

With that script I am setting the palette explicitly. That is why it works.

What I want to avoid is having to set the palette explicitly to make it work.

In all systems (except mine right now) I get a nice looking colourful plot without explicitly setting the palette.

Thanks again, and sorry to bother so much… !!

Ah ok … may you have something in your rootlogon.C which sets a white palette. Try to start root with

root -n

Hmm, no, that didn’t change anything.

If you are obliged to set the palette to get it right it means that the default palette has been changed somewhere … rootlogon.C was one possibility… but it can be somewhere else.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.