diff --git a/hist/hist/src/THLimitsFinder.cxx b/hist/hist/src/THLimitsFinder.cxx index 528b08303f651..0d991d31000f1 100644 --- a/hist/hist/src/THLimitsFinder.cxx +++ b/hist/hist/src/THLimitsFinder.cxx @@ -401,5 +401,12 @@ void THLimitsFinder::OptimizeLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, if (xmin +nbins*bw < umax) {nbins++; xmax = xmin +nbins*bw;} if (xmin > umin) {nbins++; xmin = xmax -nbins*bw;} } + else { + xmax = std::max(xmax + 1e-15*(xmax - xmin), std::nextafter(xmax,INFINITY)); + // If we put the upper bin limit directly at xmax, then all values at xmax will go into the overflow and will be invisible. + // So shift it slightly to the right, by at least 1e-12 when hist_xlow=-1000, hist_xup=0 and nbins = 100. + // Otherwise, it still does not plot the max data it with the reproducer at https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862 + // due to the rounding in TAxis::FindBin line: bin = 1 + int (fNbins*(x-fXmin)/(fXmax-fXmin) );. + } newbins = nbins; }