{ Double_t xAxis[9] = {2, 2.5, 3, 3.5, 4.25, 5, 6, 8.5, 12}; TH1 *hist = new TH1F("hist","title",8, xAxis); hist->SetBinContent(1,3.0263); hist->SetBinContent(2,2.5382); hist->SetBinContent(3,2.06942); hist->SetBinContent(4,1.972177); hist->SetBinContent(5,1.540279); hist->SetBinContent(6,1.230154); hist->SetBinContent(7,0.932342); hist->SetBinContent(8,0.771603); TCanvas *c = new TCanvas("can", "can", 700, 400); c->Divide(2,1); c->cd(1); hist->Draw(); TLegend *leg = new TLegend(0.5, 0.5, 0.99, 0.99); for(Int_t i = 1; i <= hist->GetNbinsX(); ++i){ Float_t x1 = hist->GetBinLowEdge(i); Float_t x2 = x1 + hist->GetBinWidth(i); Float_t y1 = hist->GetBinContent(i); Float_t y2 = y1 + .5; TBox *box = new TBox(x1, y1, x2, y2); box->SetLineColor(i); box->SetFillColor(i); Style_t style = 3454; box->SetFillStyle(style); box->Draw(); leg->AddEntry(box, Form("box %d, style %d", i, style), "lf"); } leg->Draw(); c->cd(2); hist->Draw(); leg = new TLegend(0.5, 0.5, 0.99, 0.99); for(Int_t i = 1; i <= hist->GetNbinsX(); ++i){ Float_t x1 = hist->GetBinLowEdge(i); Float_t x2 = x1 + hist->GetBinWidth(i); Float_t y1 = hist->GetBinContent(i); Float_t y2 = y1 + .5; TBox *box = new TBox(x1, y1, x2, y2); box->SetLineColor(i); box->SetFillColor(i); Style_t style = 3004; box->SetFillStyle(style); box->Draw(); leg->AddEntry(box, Form("box %d, style %d", i, style), "lf"); } leg->Draw(); }