senka
October 22, 2015, 6:12pm
1
Hello,
I am using TH2Poly, and Draw with text option. What I want is to draw histogram without the border line of bins. For example I try with $ROOTSYS/tutorials/hist/th2polyBoxes.C and modify Draw command to use “TEXT”:
{
TCanvas *ch2p2 = new TCanvas("ch2p2","ch2p2",600,400);
TH2Poly *h2p = new TH2Poly();
h2p->SetName("Boxes");
h2p->SetTitle("Boxes");
gStyle->SetPalette(1);
Int_t i,j;
Int_t nx = 40;
Int_t ny = 40;
Double_t x1,y1,x2,y2;
Double_t dx=0.2, dy=0.1;
x1 = 0.;
x2 = dx;
for (i = 0; i<nx; i++) {
y1 = 0.;
y2 = dy;
for (j = 0; j<ny; j++) {
h2p->AddBin(x1, y1, x2, y2);
y1 = y2;
y2 = y2+y2*dy;
}
x1 = x2;
x2 = x2+x2*dx;
}
TRandom ran;
for (i = 0; i<300000; i++) {
h2p->Fill(50*ran.Gaus(2.,1), ran.Gaus(2.,1));
}
h2p->Draw("text");
return ch2p2;
}
Output is in the attach. By default there is a black line around every bin. How can I remove it?
Thank you in advance!
couet
October 23, 2015, 9:26am
2
{
TCanvas *ch2p2 = new TCanvas("ch2p2","ch2p2",600,400);
TH2Poly *h2p = new TH2Poly();
h2p->SetName("Boxes");
h2p->SetTitle("Boxes");
gStyle->SetPalette(1);
Int_t i,j;
Int_t nx = 40;
Int_t ny = 40;
Double_t x1,Y1,x2,y2;
Double_t dx=0.2, dy=0.1;
x1 = 0.;
x2 = dx;
for (i = 0; i<nx; i++) {
Y1 = 0.;
y2 = dy;
for (j = 0; j<ny; j++) {
h2p->AddBin(x1, Y1, x2, y2);
Y1 = y2;
y2 = y2+y2*dy;
}
x1 = x2;
x2 = x2+x2*dx;
}
TRandom ran;
for (i = 0; i<300000; i++) {
h2p->Fill(50*ran.Gaus(2.,1), ran.Gaus(2.,1));
}
TList *bins = h2p->GetBins(); TIter Next(bins);
TObject *obj;
TH2PolyBin *b;
TGraph *g;
while ((obj = Next())) {
b = (TH2PolyBin*)obj;
g = (TGraph*)b->GetPolygon();
if (g) g->SetLineWidth(0);
}
h2p->Draw("text");
}
senka
October 23, 2015, 10:06am
3
Hi,
thank you for your reply, but I still get the lines, the plot looks the same as before. I am using this root:
/cvmfs/cms.cern.ch/slc6_amd64_gcc491/cms/cmssw/CMSSW_7_4_7/external/slc6_amd64_gcc491/bin/root
Greetings,
Senka
couet
October 23, 2015, 11:45am
4
Ah your root is too old … ok let me find an other way to erase the line.
couet
October 23, 2015, 11:52am
5
try:
if (g) g->SetLineColor(0)