# Plotting data from txt file

**URL:** <https://root-forum.cern.ch/t/plotting-data-from-txt-file/41900>\
**Category:** Newbie\
**Created:** [October 18, 2020, 5:28pm UTC](https://root-forum.cern.ch/t/plotting-data-from-txt-file/41900 "2020-10-18T17:28:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shoaib\_Noor](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shoaib_noor/32/23706_2.png) [@Shoaib\_Noor](https://root-forum.cern.ch/u/Shoaib_Noor)\
**Post date:** [October 18, 2020, 5:28pm UTC](https://root-forum.cern.ch/t/plotting-data-from-txt-file/41900/1 "2020-10-18T17:28:13Z")

</div>

Hi, I am trying to plot the following .txt data:  
[ER.txt](https://root-forum.cern.ch/uploads/short-url/cjy0SuCqxWhjbV2grlacppBrTJZ.txt) (191 Bytes)  
with the following code:  
[ERes.cpp](https://root-forum.cern.ch/uploads/short-url/1JO3s299LhBrZA9lSXBun5rwbT9.cpp) (484 Bytes)  
On compiling I get only one graph in place of 4:

 ![c1](https://root-forum.cern.ch/uploads/default/original/3X/a/d/adf7b765fceae53f43dad467cdd2d8216e0beb0b.jpeg)  
Please resolve,  
Thanks.

_ROOT Version:_ 6.20  
_Platform:_ Ubuntu 20.04  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![hvsouza](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hvsouza/32/23711_2.png) [@hvsouza](https://root-forum.cern.ch/u/hvsouza)\
**Post date:** [October 18, 2020, 7:28pm UTC](https://root-forum.cern.ch/t/plotting-data-from-txt-file/41900/2 "2020-10-18T19:28:45Z")

</div>

Hello,

You need to create a Canvas for each graph.  
Try something like:

```auto
  TCanvas *c1 = new TCanvas();
  c1->cd();
  gr1->SetMarkerStyle(1);gr1->Draw("ap");
  TCanvas *c2 = new TCanvas();
  c2->cd();
  gr2->SetMarkerStyle(4);gr2->Draw("ap");
  TCanvas *c3 = new TCanvas();
  c3->cd();
  gr3->SetMarkerStyle(4);gr3->Draw("ap");
  TCanvas *c4 = new TCanvas();
  c4->cd();
  gr4->SetMarkerStyle(4);gr4->Draw("ap"); 

```

Cheers,  
Henrique

---

<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 19, 2020, 6:47am UTC](https://root-forum.cern.ch/t/plotting-data-from-txt-file/41900/3 "2020-10-19T06:47:59Z")

</div>

Or divide the canvas in 4 areas:

```auto
  TCanvas *c1 = new TCanvas();
  c1->Divide(2,2);
  c1->cd(1);
  gr1->SetMarkerStyle(1);gr1->Draw("ap");
  c1->cd(2);
  gr2->SetMarkerStyle(4);gr2->Draw("ap");
  c1->cd(3);
  gr3->SetMarkerStyle(4);gr3->Draw("ap");
  c1->cd(4);
  gr4->SetMarkerStyle(4);gr4->Draw("ap"); 

```

---

<div class="post-metadata">

**Author:** ![Shoaib\_Noor](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shoaib_noor/32/23706_2.png) [@Shoaib\_Noor](https://root-forum.cern.ch/u/Shoaib_Noor)\
**Post date:** [October 19, 2020, 9:58am UTC](https://root-forum.cern.ch/t/plotting-data-from-txt-file/41900/4 "2020-10-19T09:58:36Z")

</div>

yeah that works.  
thank you Henrique & Olivier.
