# TGraphErrors X axis range

**URL:** <https://root-forum.cern.ch/t/tgrapherrors-x-axis-range/16763>\
**Category:** ROOT\
**Created:** [October 15, 2013, 3:54pm UTC](https://root-forum.cern.ch/t/tgrapherrors-x-axis-range/16763 "2013-10-15T15:54:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lloyd](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@Lloyd](https://root-forum.cern.ch/u/Lloyd)\
**Post date:** [October 15, 2013, 3:54pm UTC](https://root-forum.cern.ch/t/tgrapherrors-x-axis-range/16763/1 "2013-10-15T15:54:57Z")

</div>

I want to plot multiple data sets into a TGraphErrors with a fixed x axis range of [0, 360]

```auto
    TCanvas canvas;
    vector<TGraphErrors*> graphs;

    for (int i=0; i<inputRunNumbers.size(); i++) {
        stringstream filenameIntegrityData;
        filenameIntegrityData << inputRunNumbers.at(i) << "/TimeOfFlightScanData.dat";
        matrix_double inputIntegrityData;
        vector<double> inputSubRunNumbers, inputAzimuthalAngles, inputFlightTimes, inputFlightTimesErr;
        read_ascii_file(filenameIntegrityData, inputIntegrityData);
        inputSubRunNumbers = inputIntegrityData.at(0);
        inputAzimuthalAngles = inputIntegrityData.at(1);
        inputFlightTimes = inputIntegrityData.at(2);
        inputFlightTimesErr = inputIntegrityData.at(3);
        graphs.push_back(new TGraphErrors());

        for (int j=0; j<inputSubRunNumbers.size(); j++) {
            double tof = fmod(inputFlightTimes[j], repetitionTime);
            if (tof < 0) tof += repetitionTime;
            graphs.back()->SetPoint(inputSubRunNumbers[j], inputAzimuthalAngles[j], tof);
            graphs.back()->SetPointError(inputSubRunNumbers[j], .0, inputFlightTimesErr[j]);
        }

        graphs.back()->SetMarkerStyle(7);
        graphs.back()->SetMarkerColor(2+i);

        if(i==0) {
            graphs.back()->Draw("AP");
            graphs.back()->GetXaxis()->SetRangeUser(0, 360.0);
            graphs.back()->GetYaxis()->SetRangeUser(0, repetitionTime);
            graphs.back()->Draw("AP");
            canvas.Update();
        }
        else {
            graphs.back()->Draw("P");
            canvas.Update();
        }
    }

```

(inside a for-loop)

However, since the first data set goes only from 0 to ~120, the line

```auto
graphs.back()->GetXaxis()->SetRangeUser(0, 360.0);
```

is ignored. Could someone give me a hint? Why the heck is it not possible in ROOT to force an x axis range wider than the data?

Best thanks, Nicholas

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [October 16, 2013, 8:18am UTC](https://root-forum.cern.ch/t/tgrapherrors-x-axis-range/16763/2 "2013-10-16T08:18:49Z")

</div>

see:

> [@How to set ranges on axis?](https://root-forum.cern.ch/t/how-to-set-ranges-on-axis/28254):
>
> The viewing range for a histogram axis can be set from bin ifirst to ilast using the method TAxis::SetRange(ifirst, ilast). Example (hpxpy is a 2D histogram): { TFile f("hsimple.root"); hpxpy-\>Draw("colz"); hpxpy-\>GetYaxis()-\>SetRange(22,23); hpxpy-\>GetXaxis()-\>SetRange(18,19); } Sometimes it is more convenient to set this range using “User’s Coordinates” (axis values) rather than bin numbers. To do that one should use TAxis::SetRangeUser(ufirst, ulast). This method computes the cl…
