Get coordinates around TH2 bin contents

What are some ways I can find the Xmin, Xmax, Ymin, Ymax coordinates of a box that surrounds the rectangle of bins in this plot?

Hi,

if you know for sure it’s a rectangle, you can loop over non-empty bins and find Xmin, Xmax, Ymin, and Ymax by comparing bins centers.

May be this can help:

root.cern.ch/doc/master/classTH … 4ac3988cd3 FindFirstBinAbove
root.cern.ch/doc/master/classTH … c0d626a255 FindLastBinAbove

Thank you yus and couet! I am very grateful for your advice. This worked well for me.

``````  double llx, ulx;
llx = h->GetXaxis()->GetBinCenter(h->FindFirstBinAbove(0,1));
ulx = h->GetXaxis()->GetBinCenter(h->FindLastBinAbove(0,1));
cout << "lower limit x= " << llx << endl;
cout << "upper limit x= " << ulx << endl;
double lly, uly;
lly = h->GetYaxis()->GetBinCenter(h->FindFirstBinAbove(0,2));
uly = h->GetYaxis()->GetBinCenter(h->FindLastBinAbove(0,2));
cout << "lower limit y= " << lly << endl;
cout << "upper limit y= " << uly << endl;``````