I have histograms that have positive and negative entries. If I supply a fill color and use TH1::Draw() - I get the top plot below. If I use TH1::Draw(“lf2”), I get the bottom plot. Is there a way to get a smooth outline (bottom plot) AND fill between zero and histogram contents (top plot)? Thanks…
Ed Oltman
Have you an example showing your problem ? here is one I derived from hsimple.C, and it does what you want.
{
// Create a new canvas.
c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
c1->SetFillColor(42);
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderSize(6);
c1->GetFrame()->SetBorderMode(-1);
hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
hpx->SetFillColor(48);
// Fill histograms randomly
gRandom->SetSeed();
Float_t px, py, pz;
const Int_t kUPDATE = 1000;
for (Int_t i = 0; i < 25000; i++) {
gRandom->Rannor(px,py);
pz = px*px + py*py;
Float_t random = gRandom->Rndm(1);
if(px<0){
hpx->Fill(px,-1);
} else {
hpx->Fill(px);
}
if (i && (i%kUPDATE) == 0) {
if (i == kUPDATE) hpx->Draw("C");
c1->Modified();
c1->Update();
if (gSystem->ProcessEvents())
break;
}
}
}
Yes, the Draw(“C”) does what I want - thanks!
Note: there is a slight bug - if you zoom to a region where the histogram value<0 (e.g. x<0 in your example), the fill extends above the frame limits.
Ed
PS - you asked if I had an example - can’t you see the attached .gif I included?
I will check the slight bug you mentionned.
Yes, I saw you plot but I was interrested in the macro which produced it. I could not make an example reproducing what you show on that plot.
Hi Ed,
[quote]
Note: there is a slight bug - if you zoom to a region where the histogram value<0 (e.g. x<0 in your example), the fill extends above the frame limits. [/quote]
This problem is now fixed.
Olivier