Skip to content

[hist] clip color to minimum if below with COLZ TH2 #19441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions hist/histpainter/src/THistPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,11 @@ painted with the color corresponding to the new maximum.
When the minimum of the histogram is set to a greater value than the real minimum,
the bins having a value between the real minimum and the new minimum are not drawn
unless the option `0` is set.
In other words, option `COLZ0` forces the painting of bins with content < set minimum with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding this note ? it repeats what is already said

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not specify that it depends on whether minimum is negative or positive, right?

a color corresponding to the set minimum. In contrast, option `COLZ` would not draw values
smaller than the specified minimum. Note that both `COLZ` and `COLZ0` still do not draw
empty bins, ie bins with `content == error == 0`, if the set min is not negative.
(Note that option `COLZ0` for TH2Poly has a different behavior than for TH2.)

The following example illustrates the option `0` combined with the option `COL`.

Expand All @@ -1129,11 +1134,18 @@ Begin_Macro(source)
hcol22->SetBit(TH1::kNoStats);
c1->cd(1); hcol21->Draw("COLZ");
c1->cd(2); hcol22->Draw("COLZ0");
hcol21->SetMaximum(100);
hcol21->SetMinimum(40);
hcol22->SetMaximum(100);
hcol22->SetMinimum(40);
}
End_Macro

Note that the behavior of `COLZ` is not symmetric: it does not draw values below the specified minimum,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment. The original doc says it already.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find specified in the original doc what happens with empty bins, nor what happens with values above maximum.

but does draw values above the specified maximum by clipping them to the maximum color. In contrast, `COLZ0`
clips color on both lower and upper sides. Both `COLZ0` and `COLZ` exclude drawing empty bins (`content == error == 0`),
if the set minimum is not negative.

\since **ROOT version 6.09/01:**

When the option SAME (or "SAMES") is used with the option COL, the boxes' color
Expand Down Expand Up @@ -2457,7 +2469,7 @@ the option "GLLEGO".
\since **ROOT version 6.09/01**

In some cases it can be useful to not draw the empty bins. the option "0"
combined with the option "COL" et COLZ allows to do that.
combined with the option "COL" and "COLZ" allows to do that.

Begin_Macro(source)
{
Expand Down Expand Up @@ -5903,7 +5915,7 @@ void THistPainter::PaintColorLevels(Option_t*)
}
}
} else {
color = Int_t(0.01+(z-zmin)*scale);
color = Hoption.Zero ? Int_t(0.01+(std::max(z, zmin)-zmin)*scale) : Int_t(0.01+(z-zmin)*scale);
}

Int_t theColor = Int_t((color+0.99)*Float_t(ncolors)/Float_t(ndivz));
Expand Down Expand Up @@ -10126,6 +10138,9 @@ void THistPainter::PaintText(Option_t *)

// 2D histograms
} else {
Double_t zmin = Hparam.zmin;
if (Hoption.Logz) zmin = TMath::Power(10,Hparam.zmin);

text.SetTextAlign(22);
if (Hoption.Text == 1) angle = 0;
text.SetTextAngle(angle);
Expand All @@ -10145,7 +10160,7 @@ void THistPainter::PaintText(Option_t *)
}
if (!IsInside(x,y)) continue;
z = fH->GetBinContent(bin);
if (z < Hparam.zmin || (z == 0 && !Hoption.MinimumZero)) continue;
if (z < zmin || (z == 0 && !Hoption.MinimumZero)) continue;
if (Hoption.Text>2000) {
e = fH->GetBinError(bin);
tf.Form("#splitline{%s%s}{#pm %s%s}",
Expand Down
Loading