# Plotting part of a txt file

**URL:** <https://root-forum.cern.ch/t/plotting-part-of-a-txt-file/48530>\
**Category:** Newbie\
**Created:** [January 24, 2022, 12:54pm UTC](https://root-forum.cern.ch/t/plotting-part-of-a-txt-file/48530 "2022-01-24T12:54:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cozimus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@cozimus](https://root-forum.cern.ch/u/cozimus)\
**Post date:** [January 24, 2022, 12:54pm UTC](https://root-forum.cern.ch/t/plotting-part-of-a-txt-file/48530/1 "2022-01-24T12:54:12Z")

</div>

I’m doing a pretty easy task, but I can’t find a simple way to do this.  
I want to plot only a part of a txt file, which looks like:

```auto
#First part
2 1.96E-02
4 2.57E-02
12 2.81E-02
20 3.12E-02
28 3.17E-02
35 3.19E-02
#Second part
30 3.16E-02
28 3.19E-02
34 3.22E-02
31 3.17E-02	

```

For the moment the only solution I found was to split the file in two (part\_1.txt, part\_2.txt) and the do:

```auto
   TCanvas *c1 = new TCanvas("c1");
   c1->Divide(1,2);

   c1->cd(1);
   TGraphErrors *gr1 = new TGraphErrors("part_1.txt","%lg %lg");
   gr1->SetMarkerColor(kRed);
   gr1->SetMarkerStyle(20);
   gr1->Draw("AP");
   
   c1->cd(2);
   TGraphErrors *gr2 = new TGraphErrors("part_2.txt","%lg %lg");
   gr2->SetMarkerColor(kBlue);
   gr2->SetMarkerStyle(20);
   gr2->Draw("AP");

```

which looks like my desired result.  
Is there a way to read (or plot) olny a part of a txt file, maybe using the range of rows?

---

<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:** [January 24, 2022, 3:56pm UTC](https://root-forum.cern.ch/t/plotting-part-of-a-txt-file/48530/2 "2022-01-24T15:56:49Z")

</div>

In the [TGraph constructor from a file](https://root.cern/doc/master/classTGraph.html#ab902beb9e0463b225f0f384b6826a434) there no parameter allowing to do that, like for instance a line number to start the reading. The file is always read completely. I think the best way in your case would be to do a classical C++ file reading and fill the TGraph with the points you want.
