Graph + Histogram - Setting Axis Range


I have a very basic problem. I need to superimpose a filled Graph to a histogram and then set the axis range to the min and max values in the Graph. Here is the simplified code:

TGraph *g1 = new TGraph(“file.dat”);
TGraph2D *g2D = new TGraph2D(“file2.dat”);
TH2D *h1 = g2D->GetHistogram();

Since I draw h1 first, it fixes the axis range using h1’s bins and I can not change it to set the range to g1 min/max values. Is there a simple way to do it without having to modify my histogram (h1)?


Compute the xmin,max,ymin,max of your graph, then

TCanvas *c1 = new TCanvas; c1->DrawFrame(xmin,ymin,xmax,ymax); h1->Draw("col same"); g1->Draw("F1");