h2->Draw("COLZ");
gPad->Update();
TPaletteAxis *palette =
(TPaletteAxis*)h2->GetListOfFunctions()->FindObject("palette");
Int_t ci = palette->GetValueColor(30.);
Then it is possible to retrieve the RGB components in the following way:
TColor *c = gROOT->GetColor(ci);
float x,y,z;
c->GetRGB(x,y,z);
This function is used by TPaletteAxis::GetBinColor().
{
gStyle->SetOptFit(1);
TGraph *gr = new TGraph(2);
gr->SetPoint(0,1,1);
gr->SetPoint(1,2,2);
TLatex *l1 = new TLatex(gr->GetX()[0], gr->GetY()[0], "#1");
gr->GetListOfFunctions()->Add(l1);
gr->Draw("APL");
}
{
gStyle->SetOptFit(1111);
h = new TH1F("h","h", 2,0.,1.);
h->SetBinContent(1, 5E8);
h->SetBinError(1, 4.9E8);
h->Fit("pol0");
}
{
TCanvas* canvas = new TCanvas("Canvas", "Canvas", 0, 0, 1000, 500);
canvas->Divide(2,1);
THStack* stack = new THStack("Stack", "StackTitle");
TH1F* hist1 = new TH1F("Hist1", "Title1", 1, 0, 100);
TH1F* hist2 = new TH1F("Hist2", "Title2", 1, 0, 100);
hist1->SetFillColor(kBlack);
hist2->SetFillColor(kGray);
for (int i = 0; i < 4; ++i) {
char dataName[50];
sprintf(dataName, "Data%d", i);
hist1->Fill(dataName, 10 + 50*i);
hist2->Fill(dataName, 145 - 40*i);
}
stack->Add(hist1);
stack->Add(hist2);
canvas->cd(1); stack->Draw("nostack,bar");
canvas->cd(2); stack->Draw("nostack,hbar");
}
{
TH1F * h1 = new TH1F("h1", "h1", 100, -3., 3.);
TH1F * h2 = new TH1F("h2", "h2", 100, -3., 3.);
h1->FillRandom("gaus", 5000);
h2->FillRandom("gaus", 4000);
h1->SetMaximum(100);
h1->Draw();
h2->Draw("same");
}
{
TCanvas *c1 = new TCanvas();
gPad->DrawFrame(-1,-1,3,3);
TGraph * graph=new TGraph(3);
graph->SetFillColor(3);
graph->SetFillStyle(3001);
graph->SetLineWidth(2000);
graph->SetPoint(0,1.,1.);
graph->SetPoint(1,1.,0);
graph->SetPoint(2,0.,0.);
graph->Draw("*L");
}