# Draw scatter plot with fixed boundary

Hi,

I’d like to draw a scatter plot like tree->Draw(“x:y”) with fixed
boundary. So I draw an empty TH2F and tree->Draw(“x:y”,"",“same”) but
I got a funny result. The following is a simple macro that does it:

``````void test(Int_t option=1) {
Float_t x,y;
TTree *tree= new TTree("tree","random");
tree->Branch("x",&x,"x/F");
tree->Branch("y",&y,"y/F");
TRandom rand;
for (Int_t i=0;i<1000;i++) {
x= rand.Gaus(0,1);
y= rand.Gaus(0,1);
tree->Fill();
}

TH2F h("h","empty",100,-4,4,100,-4,4);
TCanvas *canv= new TCanvas("canv","canv",500,400);
switch (option) {
case 1:
tree->Draw("x:y");
break;
case 2:
h.Draw("A");
tree->Draw("x:y","","same");
break;
default:
}
canv->SaveAs("test.eps");
}``````

Option 1 draws 2D plot where the points are exactly at the
coordinate (x,y) but the boundary of the plot depends on
the distribution.
Option 2 gives me axes from the TH2F and points comfined within a 1x1
box. What did I do wrong? What’s the correct way to achieve my purpose:
draw scatter plot without binning effect and the boundary of
the plot does not depend on the distribution of the plot?
I know I can fill TH2F first and draw it, but I would prefer not to do
it that way because of binning effect.

I am using 3.10/02 .

Add
canv->Update();
after the line
h->Draw();

see TCanvas::Update in Users Guide.
Without Update, the histogram is not yet paint in the canvas.
the user range is the default range [0,1]

Rene