Dear ROOT experts,

I’ve made a simple bar chart by TGraph. Now I need to change the bar width and X-axis range. How can I do this?

Thanks in advance

Dear ROOT experts,

I’ve made a simple bar chart by TGraph. Now I need to change the bar width and X-axis range. How can I do this?

Thanks in advance

```
void graph() {
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2)-5;
}
TGraph *gr = new TGraph(n,x,y);
gr->SetTitle("Hello");
gr->SetMarkerStyle(20);
gStyle->SetBarWidth(0.5);
gr->Draw("A B");
}
```

1 Like

```
void graph() {
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2)-5;
}
TGraph *gr = new TGraph(n,x,y);
gr->SetTitle("Hello");
gr->SetMarkerStyle(20);
gStyle->SetBarWidth(0.5);
gr->Draw("A B");
}
```

Thanks a lot for your answer. I used gstyle->… to change bar width. one of my problems has been solved. But still I don’t know how to change X-axis range.

it would be gr->GetXaxis()->SetRangeUser(0.,1.);

But I see a clipping issue.