Option "pcol/surf1" in Draw to get coloured 2D TGraph on z-axis not working

Hi all,

sorry for this naive question.
Following these instructions: ROOT: TGraph2D Class Reference,
in my code I have been trying to display my 2D TGraph coloured on z-axis, with option:

gStyle->SetPalette(1);
graph2D->Draw("pcol");     

and then I write it into a root file, like:

graph2D->Write("graph2D");

but the 2D graph still appears to be black and white (as empty circles)
I also tried with option “surf1”, but it is not working either.
Moreover, I tried to draw(“pcol”) directly in TBrowser window, not working there either.
Libraries I am using are simply: #include <TStyle.h>, #include <TGraph2D.h>.

Any hints of what I am missing?

Thanks in advance.

You mean. when you read back the ROOT file the palette does not show ?

Exactly.
When I open with TBrowser the root file to check my 2D TGraph in it, such graph appears black and white, no colours at all.
Then I also write directly the option “pcol” in the Draw window of TBrowser and nothing changes.

When you read back the graph you should do:

root [0] auto f = new TFile("the_file_where_is_stored_the_graph.root");
root [1] gStyle->SetPalette(1); // The palette is not stored
root [2] Graph2D->Draw("PCOL"); // the drawing option is not stored

Okay, I have just opened my root file, like this:

root -l myfile.root

and then I simply have done:

gStyle->SetPalette(1);
Graph2D->Draw("PCOL");

and this worked indeed! Thanks! But I do not get why palette is not stored in the code directly. I mean, how could I make it work directly within my code?

I just would like to normally open the root file as I did and then access to it with TBrowser, in order to click on the graph and see it coloured - as I usually do with other histograms/graphs I have in it.

Anyway, thanks a lot!

Put:

gStyle->SetPalette(1);

In your rootlogon.C file.