Hist 2Image

Create an image from a 2-D histogram and manipulate it.

Author: Valeriy Onuchin
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Friday, September 25, 2020 at 08:08 AM.

In [1]:
%%cpp -d
#include <TAttImage.h>
In [2]:
TCanvas *canv = new TCanvas("image", "xygaus + xygaus(5) + xylandau(10)");
canv->ToggleEventStatus();
canv->SetRightMargin(0.2);
canv->SetLeftMargin(0.01);
canv->SetTopMargin(0.01);
canv->SetBottomMargin(0.01);

Histogram as image (hist taken from draw2dopt.c)

In [3]:
TImage *img = TImage::Create();

TF2 *f2 = new TF2("f2","(xygaus + xygaus(5) + xylandau(10))",-4,4,-4,4);
Double_t params[] = {130,-1.4,1.8,1.5,1, 150,2,0.5,-2,0.5, 3600,-2,0.7,-3,0.3};
f2->SetParameters(params);
TH2D *h2 = new TH2D("h2","xygaus + xygaus(5) + xylandau(10)",100,-4,4,100,-4,4);
h2->FillRandom("f2",40000);
img->SetImage((const Double_t *)h2->GetArray(), h2->GetNbinsX() + 2,
               h2->GetNbinsY() + 2, gHistImagePalette);
img->Draw();

Draw all canvases

In [4]:
gROOT->GetListOfCanvases()->Draw()