SetPoint() in TGraph

hi.
why does my code not plot my data points from min_pt to max_pt? it plots from 0 to max_pt, did i miss something before SetPoint()?

TGraph *g_resize (TGraph *g, Double_t min_pt, Double_t max_pt)  {
  Int_t i;
  Double_t diff =max_pt- min_pt;
 
  TGraph *gg_resize = new TGraph ();

  Double_t *X = g->GetX();
  Double_t *Y = g->GetY();
  Double_t  n = g->GetN();

  for (i=0; i<n; i++) {
    if (i >= min_pt && i <= max_pt) {
      gg_resize -> SetPoint (diff, X[i], Y[i]);
      printf ("X %f Y %f\n", X[i], Y[i]);
      gg_resize->Draw("APL");
    }
  }
  return gg_resize;
}

Thanks.
Frances

The “points” in a TGraph are ALWAYS numbered from 0 to the “total number of points -1” (i.e. “MyGraph->GetN() - 1”).
Try to replace:
gg_resize -> SetPoint (diff, X[i], Y[i]);
with:
gg_resize -> SetPoint ((gg_resize->GetN()), X[i], Y[i]);
or:
gg_resize -> SetPoint ((i - ((Int_t)(min_pt + 0.5))), X[i], Y[i]);

Note: “Stat and Math Tools” is not really the right “board” for this kind of questions.