Discussion:
[ROOT] Strange FillStyle for THStack?
Christian Hansen
2005-03-08 04:16:00 UTC
Permalink
Dear Rooters,

is there anyway to stop fill styles of different
histograms in a histogram stack to mix?

For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);

The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.

One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?

Best regards
/ Christian Hansen

===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
Rene BRUN
2005-03-08 07:16:08 UTC
Permalink
Hi Christian,

This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.

Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
Hajime Nanjo
2005-03-08 08:24:18 UTC
Permalink
Dear Rene,

I also feel inconvenience for the expedted behavior of
the FillStyle for THStack.

I prepared three plots as follows and they can be created with a script
below.

Fig.1 : THStack::Draw("nostack"); //Hatches are blended.
Fig.2 : THStack::Draw(); //Hatches are blended.
Fig.3 : Stacked histograms with TH1::Draw("same"),
which can be seen as hatches are not blended.

I am satisfied with the view of Fig.1.

I feel inconvenience for the case of Fig.2.
In Fig2, the fill style of the legends don't match that of the histograms.
Moreover, if I stack many histograms with THStack,
a view of a lower stacked hisotgram becomes indistinguishable.

So I would like to present the stacked histograms with THStack like Fig.3.
I think it is helpful if THStack::Draw() support a option to present
stacked histograms like Fig.3.

Could you implement such a option someday?
Best Regards,
Hajime

/////////////////////////////////////////////////////////////////
//
{
TCanvas *c1 = new TCanvas("c1","c1",800,600);
c1->Divide(2,2);

//-------------------------------------------
TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
h1->FillRandom("gaus",10000);
//-------------------------------------------
TF1* gaus = (TF1*)gROOT->FindObject("gaus");
gaus->SetParameter(1,1.5);
gaus->SetParameter(2,0.3);
TH1F *h2 = new TH1F("h2","Histo 2",100,-5,5);
h2->FillRandom("gaus",20000);
//-------------------------------------------
h1->SetFillStyle(3004);
h1->SetFillColor(1);
h2->SetFillStyle(3005);
h2->SetFillColor(1);
//-------------------------------------------
THStack *hs = new THStack("hs","A stack of histograms");
hs->Add(h1);
hs->Add(h2);
//-------------------------------------------
TLegend *leg = new TLegend(0.1,0.6,0.4,0.9);
leg->AddEntry(h1,"h1","f");
leg->AddEntry(h2,"h2","f");
//-------------------------------------------


//-------------------------------------------
c1->cd(1);
hs->SetTitle("hatch THStack::Draw(\"nostack\")");
hs->DrawClone("nostack");
leg->DrawClone();
//-------------------------------------------


//-------------------------------------------
c1->cd(2);
hs->SetTitle("hatch THStack::Draw()");
hs->DrawClone();
leg->DrawClone();
//-------------------------------------------


//-------------------------------------------
c1->cd(3);
TH1F* h0 = (TH1F*)h1->Clone("h0");
h0->SetTitle("hatch TH1F::Draw(\"same\")");
h0->Add(h2);
h0->SetStats(0);
TH1F* h1w = (TH1F*)h1->Clone("h1w");
h0->SetFillStyle(h2->GetFillStyle());
h0->SetFillColor(h2->GetFillColor());
h1w->SetFillStyle(1001);
h1w->SetFillColor(c1->GetFillColor());
h0->DrawClone();
h1w->DrawClone("same");
h1->DrawClone("same");
TLegend *leg2 = new TLegend(0.1,0.6,0.4,0.9);
leg2->AddEntry(h1,"h1","f");
leg2->AddEntry(h0,"h2","f");
leg2->DrawClone();
delete h0;
delete h1w;
delete leg2;
//-------------------------------------------


c1->cd();
c1->SaveAs("c1.ps");

}
/////////////////////////////////////////////////////////////////
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
Christian Hansen
2005-03-08 14:52:18 UTC
Permalink
On Tue, 8 Mar 2005, Hajime Nanjo wrote:

Thank you very much Hajime!

I've used your code in my program now and it works as
I wanted. Thanks!

/Christian
Post by Hajime Nanjo
Dear Rene,
I also feel inconvenience for the expedted behavior of
the FillStyle for THStack.
I prepared three plots as follows and they can be created with a script
below.
Fig.1 : THStack::Draw("nostack"); //Hatches are blended.
Fig.2 : THStack::Draw(); //Hatches are blended.
Fig.3 : Stacked histograms with TH1::Draw("same"),
which can be seen as hatches are not blended.
I am satisfied with the view of Fig.1.
I feel inconvenience for the case of Fig.2.
In Fig2, the fill style of the legends don't match that of the histograms.
Moreover, if I stack many histograms with THStack,
a view of a lower stacked hisotgram becomes indistinguishable.
So I would like to present the stacked histograms with THStack like Fig.3.
I think it is helpful if THStack::Draw() support a option to present
stacked histograms like Fig.3.
Could you implement such a option someday?
Best Regards,
Hajime
/////////////////////////////////////////////////////////////////
//
{
TCanvas *c1 = new TCanvas("c1","c1",800,600);
c1->Divide(2,2);
//-------------------------------------------
TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
h1->FillRandom("gaus",10000);
//-------------------------------------------
TF1* gaus = (TF1*)gROOT->FindObject("gaus");
gaus->SetParameter(1,1.5);
gaus->SetParameter(2,0.3);
TH1F *h2 = new TH1F("h2","Histo 2",100,-5,5);
h2->FillRandom("gaus",20000);
//-------------------------------------------
h1->SetFillStyle(3004);
h1->SetFillColor(1);
h2->SetFillStyle(3005);
h2->SetFillColor(1);
//-------------------------------------------
THStack *hs = new THStack("hs","A stack of histograms");
hs->Add(h1);
hs->Add(h2);
//-------------------------------------------
TLegend *leg = new TLegend(0.1,0.6,0.4,0.9);
leg->AddEntry(h1,"h1","f");
leg->AddEntry(h2,"h2","f");
//-------------------------------------------
//-------------------------------------------
c1->cd(1);
hs->SetTitle("hatch THStack::Draw(\"nostack\")");
hs->DrawClone("nostack");
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(2);
hs->SetTitle("hatch THStack::Draw()");
hs->DrawClone();
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(3);
TH1F* h0 = (TH1F*)h1->Clone("h0");
h0->SetTitle("hatch TH1F::Draw(\"same\")");
h0->Add(h2);
h0->SetStats(0);
TH1F* h1w = (TH1F*)h1->Clone("h1w");
h0->SetFillStyle(h2->GetFillStyle());
h0->SetFillColor(h2->GetFillColor());
h1w->SetFillStyle(1001);
h1w->SetFillColor(c1->GetFillColor());
h0->DrawClone();
h1w->DrawClone("same");
h1->DrawClone("same");
TLegend *leg2 = new TLegend(0.1,0.6,0.4,0.9);
leg2->AddEntry(h1,"h1","f");
leg2->AddEntry(h0,"h2","f");
leg2->DrawClone();
delete h0;
delete h1w;
delete leg2;
//-------------------------------------------
c1->cd();
c1->SaveAs("c1.ps");
}
/////////////////////////////////////////////////////////////////
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
--
/ Christian Hansen

===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
Christian Hansen
2005-03-08 14:05:02 UTC
Permalink
Hi Rene,

This is maybe the technically expected behaviour but normally not
the physically wanted behaviour. For example the h3 is added on top
of h2 and h1 and does not fill behind h2 and h1, so why should the
pattern of h3 (green vertical lines) be shown on the area of h2
and h1?
As another example, imagine this plot (upper left) to be in a paper,
and if one want to refer to h1 in the text as the area with the
horisontally lines, one cannot since there are also vertical and
leaning lines above it.
I therefore strongly recomend that their should be a way to fill
the area of a histogram with the style of only that histogram.

Best wishes
/Christian
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
--
/ Christian Hansen

===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
Olivier Couet
2005-03-08 14:34:37 UTC
Permalink
Hi Christian,

We got the same question from Hajime Nanjo. I am working on that problem.

Cheers, Olivier
Post by Christian Hansen
Hi Rene,
This is maybe the technically expected behaviour but normally not
the physically wanted behaviour. For example the h3 is added on top
of h2 and h1 and does not fill behind h2 and h1, so why should the
pattern of h3 (green vertical lines) be shown on the area of h2
and h1?
As another example, imagine this plot (upper left) to be in a paper,
and if one want to refer to h1 in the text as the area with the
horisontally lines, one cannot since there are also vertical and
leaning lines above it.
I therefore strongly recomend that their should be a way to fill
the area of a histogram with the style of only that histogram.
Best wishes
/Christian
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
--
Org: CERN - European Laboratory for Particle Physics.
Mail: 1211 Geneve 23 - Switzerland Mailbox: J25910
E-Mail: ***@cern.ch Phone: +41 22 7676522
WWW: http://cern.ch/Olivier.Couet/ Fax: +41 22 7670300
Olivier Couet
2005-03-08 15:37:48 UTC
Permalink
Oh yes, you are right. Sorry. In fact is why I would like to inmplement in
THStack::Paint

Olivier
Hi Olivier,
it is important that the canvas has a fill colour, since
this one is used to overwrite the lines of the other
histogram;
h1w->SetFillColor(c1->GetFillColor());
To be sure, I added this line
c1->SetFillColor(10);
after the TCanvas decleration.
Hope this helps, otherwice I don't know
Cheers
/Christian
Hi Hajime and Christian,
For me Fig 2 and Fig 3 of Hajime example are in the same. See the
attached PS file I got.
Cheers, Olivier
Post by Christian Hansen
Thank you very much Hajime!
I've used your code in my program now and it works as
I wanted. Thanks!
/Christian
Post by Hajime Nanjo
Dear Rene,
I also feel inconvenience for the expedted behavior of
the FillStyle for THStack.
I prepared three plots as follows and they can be created with a script
below.
Fig.1 : THStack::Draw("nostack"); //Hatches are blended.
Fig.2 : THStack::Draw(); //Hatches are blended.
Fig.3 : Stacked histograms with TH1::Draw("same"),
which can be seen as hatches are not blended.
I am satisfied with the view of Fig.1.
I feel inconvenience for the case of Fig.2.
In Fig2, the fill style of the legends don't match that of the histograms.
Moreover, if I stack many histograms with THStack,
a view of a lower stacked hisotgram becomes indistinguishable.
So I would like to present the stacked histograms with THStack like Fig.3.
I think it is helpful if THStack::Draw() support a option to present
stacked histograms like Fig.3.
Could you implement such a option someday?
Best Regards,
Hajime
/////////////////////////////////////////////////////////////////
//
{
TCanvas *c1 = new TCanvas("c1","c1",800,600);
c1->Divide(2,2);
//-------------------------------------------
TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
h1->FillRandom("gaus",10000);
//-------------------------------------------
TF1* gaus = (TF1*)gROOT->FindObject("gaus");
gaus->SetParameter(1,1.5);
gaus->SetParameter(2,0.3);
TH1F *h2 = new TH1F("h2","Histo 2",100,-5,5);
h2->FillRandom("gaus",20000);
//-------------------------------------------
h1->SetFillStyle(3004);
h1->SetFillColor(1);
h2->SetFillStyle(3005);
h2->SetFillColor(1);
//-------------------------------------------
THStack *hs = new THStack("hs","A stack of histograms");
hs->Add(h1);
hs->Add(h2);
//-------------------------------------------
TLegend *leg = new TLegend(0.1,0.6,0.4,0.9);
leg->AddEntry(h1,"h1","f");
leg->AddEntry(h2,"h2","f");
//-------------------------------------------
//-------------------------------------------
c1->cd(1);
hs->SetTitle("hatch THStack::Draw(\"nostack\")");
hs->DrawClone("nostack");
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(2);
hs->SetTitle("hatch THStack::Draw()");
hs->DrawClone();
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(3);
TH1F* h0 = (TH1F*)h1->Clone("h0");
h0->SetTitle("hatch TH1F::Draw(\"same\")");
h0->Add(h2);
h0->SetStats(0);
TH1F* h1w = (TH1F*)h1->Clone("h1w");
h0->SetFillStyle(h2->GetFillStyle());
h0->SetFillColor(h2->GetFillColor());
h1w->SetFillStyle(1001);
h1w->SetFillColor(c1->GetFillColor());
h0->DrawClone();
h1w->DrawClone("same");
h1->DrawClone("same");
TLegend *leg2 = new TLegend(0.1,0.6,0.4,0.9);
leg2->AddEntry(h1,"h1","f");
leg2->AddEntry(h0,"h2","f");
leg2->DrawClone();
delete h0;
delete h1w;
delete leg2;
//-------------------------------------------
c1->cd();
c1->SaveAs("c1.ps");
}
/////////////////////////////////////////////////////////////////
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
--
Org: CERN - European Laboratory for Particle Physics.
Mail: 1211 Geneve 23 - Switzerland Mailbox: J25910
E-Mail: ***@cern.ch Phone: +41 22 7676522
WWW: http://cern.ch/Olivier.Couet/ Fax: +41 22 7670300
Hajime Nanjo
2005-03-08 16:02:32 UTC
Permalink
Dear Christian and Olivier,

You are right.
For example, a possilbe solution is as follows.
//==================================================
if(gPad->GetFillColor()==0) h1w->SetFillColor(10);
else h1w->SetFillColor(c1->GetFillColor());
//==================================================

I just wanted to show the appearance I expected for the THStack::Draw()
by the short script. I think the implementation will be performed in more
elegant way. Anyway, I am happy to hear you are working on the request.
Thank you in advance.

Best Regards,
Hajime
Post by Olivier Couet
Oh yes, you are right. Sorry. In fact is why I would like to inmplement in
THStack::Paint
Olivier
Hi Olivier,
it is important that the canvas has a fill colour, since
this one is used to overwrite the lines of the other
histogram;
h1w->SetFillColor(c1->GetFillColor());
To be sure, I added this line
c1->SetFillColor(10);
after the TCanvas decleration.
Hope this helps, otherwice I don't know
Cheers
/Christian
Hi Hajime and Christian,
For me Fig 2 and Fig 3 of Hajime example are in the same. See the
attached PS file I got.
Cheers, Olivier
Post by Christian Hansen
Thank you very much Hajime!
I've used your code in my program now and it works as
I wanted. Thanks!
/Christian
Post by Hajime Nanjo
Dear Rene,
I also feel inconvenience for the expedted behavior of
the FillStyle for THStack.
I prepared three plots as follows and they can be created with a script
below.
Fig.1 : THStack::Draw("nostack"); //Hatches are blended.
Fig.2 : THStack::Draw(); //Hatches are blended.
Fig.3 : Stacked histograms with TH1::Draw("same"),
which can be seen as hatches are not blended.
I am satisfied with the view of Fig.1.
I feel inconvenience for the case of Fig.2.
In Fig2, the fill style of the legends don't match that of the histograms.
Moreover, if I stack many histograms with THStack,
a view of a lower stacked hisotgram becomes indistinguishable.
So I would like to present the stacked histograms with THStack like Fig.3.
I think it is helpful if THStack::Draw() support a option to present
stacked histograms like Fig.3.
Could you implement such a option someday?
Best Regards,
Hajime
/////////////////////////////////////////////////////////////////
//
{
TCanvas *c1 = new TCanvas("c1","c1",800,600);
c1->Divide(2,2);
//-------------------------------------------
TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
h1->FillRandom("gaus",10000);
//-------------------------------------------
TF1* gaus = (TF1*)gROOT->FindObject("gaus");
gaus->SetParameter(1,1.5);
gaus->SetParameter(2,0.3);
TH1F *h2 = new TH1F("h2","Histo 2",100,-5,5);
h2->FillRandom("gaus",20000);
//-------------------------------------------
h1->SetFillStyle(3004);
h1->SetFillColor(1);
h2->SetFillStyle(3005);
h2->SetFillColor(1);
//-------------------------------------------
THStack *hs = new THStack("hs","A stack of histograms");
hs->Add(h1);
hs->Add(h2);
//-------------------------------------------
TLegend *leg = new TLegend(0.1,0.6,0.4,0.9);
leg->AddEntry(h1,"h1","f");
leg->AddEntry(h2,"h2","f");
//-------------------------------------------
//-------------------------------------------
c1->cd(1);
hs->SetTitle("hatch THStack::Draw(\"nostack\")");
hs->DrawClone("nostack");
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(2);
hs->SetTitle("hatch THStack::Draw()");
hs->DrawClone();
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(3);
TH1F* h0 = (TH1F*)h1->Clone("h0");
h0->SetTitle("hatch TH1F::Draw(\"same\")");
h0->Add(h2);
h0->SetStats(0);
TH1F* h1w = (TH1F*)h1->Clone("h1w");
h0->SetFillStyle(h2->GetFillStyle());
h0->SetFillColor(h2->GetFillColor());
h1w->SetFillStyle(1001);
h1w->SetFillColor(c1->GetFillColor());
h0->DrawClone();
h1w->DrawClone("same");
h1->DrawClone("same");
TLegend *leg2 = new TLegend(0.1,0.6,0.4,0.9);
leg2->AddEntry(h1,"h1","f");
leg2->AddEntry(h0,"h2","f");
leg2->DrawClone();
delete h0;
delete h1w;
delete leg2;
//-------------------------------------------
c1->cd();
c1->SaveAs("c1.ps");
}
/////////////////////////////////////////////////////////////////
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
--
Org: CERN - European Laboratory for Particle Physics.
Mail: 1211 Geneve 23 - Switzerland Mailbox: J25910
WWW: http://cern.ch/Olivier.Couet/ Fax: +41 22 7670300
Olivier Couet
2005-03-09 10:38:29 UTC
Permalink
Dear Christian and Hajime,

This new scheme is now implement in the TStack painting function. (cvs
head).

Cheers, Olivier
Post by Hajime Nanjo
Dear Christian and Olivier,
You are right.
For example, a possilbe solution is as follows.
//==================================================
if(gPad->GetFillColor()==0) h1w->SetFillColor(10);
else h1w->SetFillColor(c1->GetFillColor());
//==================================================
I just wanted to show the appearance I expected for the THStack::Draw()
by the short script. I think the implementation will be performed in more
elegant way. Anyway, I am happy to hear you are working on the request.
Thank you in advance.
Best Regards,
Hajime
Post by Olivier Couet
Oh yes, you are right. Sorry. In fact is why I would like to inmplement in
THStack::Paint
Olivier
Hi Olivier,
it is important that the canvas has a fill colour, since
this one is used to overwrite the lines of the other
histogram;
h1w->SetFillColor(c1->GetFillColor());
To be sure, I added this line
c1->SetFillColor(10);
after the TCanvas decleration.
Hope this helps, otherwice I don't know
Cheers
/Christian
Hi Hajime and Christian,
For me Fig 2 and Fig 3 of Hajime example are in the same. See the
attached PS file I got.
Cheers, Olivier
Post by Christian Hansen
Thank you very much Hajime!
I've used your code in my program now and it works as
I wanted. Thanks!
/Christian
Post by Hajime Nanjo
Dear Rene,
I also feel inconvenience for the expedted behavior of
the FillStyle for THStack.
I prepared three plots as follows and they can be created with a script
below.
Fig.1 : THStack::Draw("nostack"); //Hatches are blended.
Fig.2 : THStack::Draw(); //Hatches are blended.
Fig.3 : Stacked histograms with TH1::Draw("same"),
which can be seen as hatches are not blended.
I am satisfied with the view of Fig.1.
I feel inconvenience for the case of Fig.2.
In Fig2, the fill style of the legends don't match that of the histograms.
Moreover, if I stack many histograms with THStack,
a view of a lower stacked hisotgram becomes indistinguishable.
So I would like to present the stacked histograms with THStack like Fig.3.
I think it is helpful if THStack::Draw() support a option to present
stacked histograms like Fig.3.
Could you implement such a option someday?
Best Regards,
Hajime
/////////////////////////////////////////////////////////////////
//
{
TCanvas *c1 = new TCanvas("c1","c1",800,600);
c1->Divide(2,2);
//-------------------------------------------
TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
h1->FillRandom("gaus",10000);
//-------------------------------------------
TF1* gaus = (TF1*)gROOT->FindObject("gaus");
gaus->SetParameter(1,1.5);
gaus->SetParameter(2,0.3);
TH1F *h2 = new TH1F("h2","Histo 2",100,-5,5);
h2->FillRandom("gaus",20000);
//-------------------------------------------
h1->SetFillStyle(3004);
h1->SetFillColor(1);
h2->SetFillStyle(3005);
h2->SetFillColor(1);
//-------------------------------------------
THStack *hs = new THStack("hs","A stack of histograms");
hs->Add(h1);
hs->Add(h2);
//-------------------------------------------
TLegend *leg = new TLegend(0.1,0.6,0.4,0.9);
leg->AddEntry(h1,"h1","f");
leg->AddEntry(h2,"h2","f");
//-------------------------------------------
//-------------------------------------------
c1->cd(1);
hs->SetTitle("hatch THStack::Draw(\"nostack\")");
hs->DrawClone("nostack");
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(2);
hs->SetTitle("hatch THStack::Draw()");
hs->DrawClone();
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(3);
TH1F* h0 = (TH1F*)h1->Clone("h0");
h0->SetTitle("hatch TH1F::Draw(\"same\")");
h0->Add(h2);
h0->SetStats(0);
TH1F* h1w = (TH1F*)h1->Clone("h1w");
h0->SetFillStyle(h2->GetFillStyle());
h0->SetFillColor(h2->GetFillColor());
h1w->SetFillStyle(1001);
h1w->SetFillColor(c1->GetFillColor());
h0->DrawClone();
h1w->DrawClone("same");
h1->DrawClone("same");
TLegend *leg2 = new TLegend(0.1,0.6,0.4,0.9);
leg2->AddEntry(h1,"h1","f");
leg2->AddEntry(h0,"h2","f");
leg2->DrawClone();
delete h0;
delete h1w;
delete leg2;
//-------------------------------------------
c1->cd();
c1->SaveAs("c1.ps");
}
/////////////////////////////////////////////////////////////////
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
--
Org: CERN - European Laboratory for Particle Physics.
Mail: 1211 Geneve 23 - Switzerland Mailbox: J25910
WWW: http://cern.ch/Olivier.Couet/ Fax: +41 22 7670300
--
Org: CERN - European Laboratory for Particle Physics.
Mail: 1211 Geneve 23 - Switzerland Mailbox: J25910
E-Mail: ***@cern.ch Phone: +41 22 7676522
WWW: http://cern.ch/Olivier.Couet/ Fax: +41 22 7670300
Hajime Nanjo
2005-03-09 12:12:30 UTC
Permalink
Dear Olivier,

Thank you for the rapid fix.
I looked at the source code and I think it is implemented
correctly in a elegant manner. As you did, I find that
the use of "TH1::Paint()" is enough for the purpose.
I will check it soon recompiling my ROOT.

Best Regards,
Hajime
Post by Olivier Couet
Dear Christian and Hajime,
This new scheme is now implement in the TStack painting function. (cvs
head).
Cheers, Olivier
Post by Hajime Nanjo
Dear Christian and Olivier,
You are right.
For example, a possilbe solution is as follows.
//==================================================
if(gPad->GetFillColor()==0) h1w->SetFillColor(10);
else h1w->SetFillColor(c1->GetFillColor());
//==================================================
I just wanted to show the appearance I expected for the THStack::Draw()
by the short script. I think the implementation will be performed in more
elegant way. Anyway, I am happy to hear you are working on the request.
Thank you in advance.
Best Regards,
Hajime
Post by Olivier Couet
Oh yes, you are right. Sorry. In fact is why I would like to inmplement in
THStack::Paint
Olivier
Hi Olivier,
it is important that the canvas has a fill colour, since
this one is used to overwrite the lines of the other
histogram;
h1w->SetFillColor(c1->GetFillColor());
To be sure, I added this line
c1->SetFillColor(10);
after the TCanvas decleration.
Hope this helps, otherwice I don't know
Cheers
/Christian
Hi Hajime and Christian,
For me Fig 2 and Fig 3 of Hajime example are in the same. See the
attached PS file I got.
Cheers, Olivier
Post by Christian Hansen
Thank you very much Hajime!
I've used your code in my program now and it works as
I wanted. Thanks!
/Christian
Post by Hajime Nanjo
Dear Rene,
I also feel inconvenience for the expedted behavior of
the FillStyle for THStack.
I prepared three plots as follows and they can be created with a script
below.
Fig.1 : THStack::Draw("nostack"); //Hatches are blended.
Fig.2 : THStack::Draw(); //Hatches are blended.
Fig.3 : Stacked histograms with TH1::Draw("same"),
which can be seen as hatches are not blended.
I am satisfied with the view of Fig.1.
I feel inconvenience for the case of Fig.2.
In Fig2, the fill style of the legends don't match that of the histograms.
Moreover, if I stack many histograms with THStack,
a view of a lower stacked hisotgram becomes indistinguishable.
So I would like to present the stacked histograms with THStack like Fig.3.
I think it is helpful if THStack::Draw() support a option to present
stacked histograms like Fig.3.
Could you implement such a option someday?
Best Regards,
Hajime
/////////////////////////////////////////////////////////////////
//
{
TCanvas *c1 = new TCanvas("c1","c1",800,600);
c1->Divide(2,2);
//-------------------------------------------
TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
h1->FillRandom("gaus",10000);
//-------------------------------------------
TF1* gaus = (TF1*)gROOT->FindObject("gaus");
gaus->SetParameter(1,1.5);
gaus->SetParameter(2,0.3);
TH1F *h2 = new TH1F("h2","Histo 2",100,-5,5);
h2->FillRandom("gaus",20000);
//-------------------------------------------
h1->SetFillStyle(3004);
h1->SetFillColor(1);
h2->SetFillStyle(3005);
h2->SetFillColor(1);
//-------------------------------------------
THStack *hs = new THStack("hs","A stack of histograms");
hs->Add(h1);
hs->Add(h2);
//-------------------------------------------
TLegend *leg = new TLegend(0.1,0.6,0.4,0.9);
leg->AddEntry(h1,"h1","f");
leg->AddEntry(h2,"h2","f");
//-------------------------------------------
//-------------------------------------------
c1->cd(1);
hs->SetTitle("hatch THStack::Draw(\"nostack\")");
hs->DrawClone("nostack");
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(2);
hs->SetTitle("hatch THStack::Draw()");
hs->DrawClone();
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(3);
TH1F* h0 = (TH1F*)h1->Clone("h0");
h0->SetTitle("hatch TH1F::Draw(\"same\")");
h0->Add(h2);
h0->SetStats(0);
TH1F* h1w = (TH1F*)h1->Clone("h1w");
h0->SetFillStyle(h2->GetFillStyle());
h0->SetFillColor(h2->GetFillColor());
h1w->SetFillStyle(1001);
h1w->SetFillColor(c1->GetFillColor());
h0->DrawClone();
h1w->DrawClone("same");
h1->DrawClone("same");
TLegend *leg2 = new TLegend(0.1,0.6,0.4,0.9);
leg2->AddEntry(h1,"h1","f");
leg2->AddEntry(h0,"h2","f");
leg2->DrawClone();
delete h0;
delete h1w;
delete leg2;
//-------------------------------------------
c1->cd();
c1->SaveAs("c1.ps");
}
/////////////////////////////////////////////////////////////////
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
--
Org: CERN - European Laboratory for Particle Physics.
Mail: 1211 Geneve 23 - Switzerland Mailbox: J25910
WWW: http://cern.ch/Olivier.Couet/ Fax: +41 22 7670300
--
Org: CERN - European Laboratory for Particle Physics.
Mail: 1211 Geneve 23 - Switzerland Mailbox: J25910
WWW: http://cern.ch/Olivier.Couet/ Fax: +41 22 7670300
Christian Hansen
2005-03-08 15:32:20 UTC
Permalink
On Tue, 8 Mar 2005, Olivier Couet wrote:

Hi Olivier,

it is important that the canvas has a fill colour, since
this one is used to overwrite the lines of the other
histogram;

h1w->SetFillColor(c1->GetFillColor());

To be sure, I added this line

c1->SetFillColor(10);

after the TCanvas decleration.
Hope this helps, otherwice I don't know

Cheers
/Christian
Hi Hajime and Christian,
For me Fig 2 and Fig 3 of Hajime example are in the same. See the
attached PS file I got.
Cheers, Olivier
Post by Christian Hansen
Thank you very much Hajime!
I've used your code in my program now and it works as
I wanted. Thanks!
/Christian
Post by Hajime Nanjo
Dear Rene,
I also feel inconvenience for the expedted behavior of
the FillStyle for THStack.
I prepared three plots as follows and they can be created with a script
below.
Fig.1 : THStack::Draw("nostack"); //Hatches are blended.
Fig.2 : THStack::Draw(); //Hatches are blended.
Fig.3 : Stacked histograms with TH1::Draw("same"),
which can be seen as hatches are not blended.
I am satisfied with the view of Fig.1.
I feel inconvenience for the case of Fig.2.
In Fig2, the fill style of the legends don't match that of the histograms.
Moreover, if I stack many histograms with THStack,
a view of a lower stacked hisotgram becomes indistinguishable.
So I would like to present the stacked histograms with THStack like Fig.3.
I think it is helpful if THStack::Draw() support a option to present
stacked histograms like Fig.3.
Could you implement such a option someday?
Best Regards,
Hajime
/////////////////////////////////////////////////////////////////
//
{
TCanvas *c1 = new TCanvas("c1","c1",800,600);
c1->Divide(2,2);
//-------------------------------------------
TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
h1->FillRandom("gaus",10000);
//-------------------------------------------
TF1* gaus = (TF1*)gROOT->FindObject("gaus");
gaus->SetParameter(1,1.5);
gaus->SetParameter(2,0.3);
TH1F *h2 = new TH1F("h2","Histo 2",100,-5,5);
h2->FillRandom("gaus",20000);
//-------------------------------------------
h1->SetFillStyle(3004);
h1->SetFillColor(1);
h2->SetFillStyle(3005);
h2->SetFillColor(1);
//-------------------------------------------
THStack *hs = new THStack("hs","A stack of histograms");
hs->Add(h1);
hs->Add(h2);
//-------------------------------------------
TLegend *leg = new TLegend(0.1,0.6,0.4,0.9);
leg->AddEntry(h1,"h1","f");
leg->AddEntry(h2,"h2","f");
//-------------------------------------------
//-------------------------------------------
c1->cd(1);
hs->SetTitle("hatch THStack::Draw(\"nostack\")");
hs->DrawClone("nostack");
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(2);
hs->SetTitle("hatch THStack::Draw()");
hs->DrawClone();
leg->DrawClone();
//-------------------------------------------
//-------------------------------------------
c1->cd(3);
TH1F* h0 = (TH1F*)h1->Clone("h0");
h0->SetTitle("hatch TH1F::Draw(\"same\")");
h0->Add(h2);
h0->SetStats(0);
TH1F* h1w = (TH1F*)h1->Clone("h1w");
h0->SetFillStyle(h2->GetFillStyle());
h0->SetFillColor(h2->GetFillColor());
h1w->SetFillStyle(1001);
h1w->SetFillColor(c1->GetFillColor());
h0->DrawClone();
h1w->DrawClone("same");
h1->DrawClone("same");
TLegend *leg2 = new TLegend(0.1,0.6,0.4,0.9);
leg2->AddEntry(h1,"h1","f");
leg2->AddEntry(h0,"h2","f");
leg2->DrawClone();
delete h0;
delete h1w;
delete leg2;
//-------------------------------------------
c1->cd();
c1->SaveAs("c1.ps");
}
/////////////////////////////////////////////////////////////////
Post by Rene BRUN
Hi Christian,
This is the expected behaviour. Each histogram in the stack is paint
on top of the previous one. One could modify the algorithm to paint
only the difference between histograms, but this requires a bit of work
to take into account correctly the bins with no content.
Rene brun
Post by Christian Hansen
Dear Rooters,
is there anyway to stop fill styles of different
histograms in a histogram stack to mix?
For example, I used $ROOTSYS/tutorials/hstack.C
and added only three lines (see attachement);
h1->SetFillStyle(3007);
h2->SetFillStyle(3004);
h3->SetFillStyle(3006);
The result from the edited hstack.C shows in the
upper left corner the stacked histograms, but now
with different fill styles.
One can see that the green vertical lines of h3
continues down and fills also h2 and h1. Is there
a way to force h1 to ONLY be filled with the red
horisontal lines, h2 to ONLY be filled with the
blue leaning lines and h3 to only be filled with
the green vertical lines?
Best regards
/ Christian Hansen
===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
------------------------------------------------------------------------
void hstack() {
// Example of stacked histograms: class THStack
//
// Author: Rene Brun
THStack *hs = new THStack("hs","test stacked histograms");
//create three 1-d histograms
TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
h1->FillRandom("gaus",20000);
h1->SetFillColor(kRed);
h1->SetFillStyle(3007); // <-- NEW
h1->SetMarkerStyle(21);
h1->SetMarkerColor(kRed);
hs->Add(h1);
TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
h2->FillRandom("gaus",15000);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3004); // <-- NEW
h2->SetMarkerStyle(21);
h2->SetMarkerColor(kBlue);
hs->Add(h2);
TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
h3->FillRandom("gaus",10000);
h3->SetFillColor(kGreen);
h3->SetFillStyle(3006); // <-- NEW
h3->SetMarkerStyle(21);
h3->SetMarkerColor(kGreen);
hs->Add(h3);
TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);
c1->SetFillColor(41);
c1->Divide(2,2);
// in top left pad, draw the stack with defaults
c1->cd(1);
hs->Draw();
// in top right pad, draw the stack in non-stack mode and errors option
c1->cd(2);
gPad->SetGrid();
hs->Draw("nostack,e1p");
//in bottom left, draw in stack mode with "lego1" option
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->SetTheta(3.77);
gPad->SetPhi(2.9);
hs->Draw("lego1");
c1->cd(4);
//create two 2-D histograms and draw them in stack mode
gPad->SetFrameFillColor(17);
THStack *a = new THStack("a","test legos");
TF2 *f1 = new TF2("f1","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};
f1->SetParameters(params);
TH2F *h2a = new TH2F("h2a","h2a",20,-4,4,20,-4,4);
h2a->SetFillColor(38);
h2a->FillRandom("f1",4000);
TF2 *f2 = new TF2("f2","xygaus + xygaus(5)",-4,4,-4,4);
Double_t params[] = {100,-1.4,1.9,1.1,2, 80,2,0.7,-2,0.5};
f2->SetParameters(params);
TH2F *h2b = new TH2F("h2b","h2b",20,-4,4,20,-4,4);
h2b->SetFillColor(46);
h2b->FillRandom("f2",3000);
a->Add(h2a);
a->Add(h2b);
a->Draw();
c1->Print("stackTest.eps");
}
--
/ Christian Hansen

===============================================
Box 535 Office: +46-(0)18-471 32 57
S-751 21 Uppsala Office: 82104
Sweden
-----------------------------------------------
Mobile : +46-(0)708-887617
Home Page : http://welcome.to/Christian_Hansen
http://www.cern.ch/Christian.Hansen
Loading...