# Three Column TextFile TH2D

**URL:** <https://root-forum.cern.ch/t/three-column-textfile-th2d/52691>\
**Category:** Newbie\
**Tags:** root\
**Created:** [December 7, 2022, 10:35pm UTC](https://root-forum.cern.ch/t/three-column-textfile-th2d/52691 "2022-12-07T22:35:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Voldemort](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/voldemort/32/28433_2.png) [@Voldemort](https://root-forum.cern.ch/u/Voldemort)\
**Post date:** [December 7, 2022, 10:35pm UTC](https://root-forum.cern.ch/t/three-column-textfile-th2d/52691/1 "2022-12-07T22:35:06Z")

</div>

Hi there,  
I’ve got a txtfile that holds 3 columns of data. Column1 would be the x-axis (date), column2 is y-axis(sensor #) and column3 is the temp. I would like to make a 2D plot where the Temperature readings are plotted with respect to the sensor number and date. I’ve attached my textfile for reference.

```auto
#include <iostream>
#include <fstream>
#include <string>
#include <list>

void sensortempvsdate()
{

	string x;
	int y;
	double z;

	TCanvas *c = new TCanvas();

	//xbin, xmin, xmax, ybin, ymin, ymax
	TH2D *hist = new TH2D("h1", "Temperature Readings", 100, '2022-04-28', '2022-06-30', 100, 30, 61);

	hist->GetXaxis()->SetTitle("Date");
	hist->GetXaxis()->CenterTitle();
	
	hist->GetYaxis()->SetTitle("Temperature Sensor");
	hist->GetYaxis()->CenterTitle();

	fstream file;
	file.open("/project/avgtemp.txt", ios::in);

	while(1)
	{
		file >> x >> y >> z;

		hist->Fill(x, y, z);
		cout << "x is " << x << endl;
		cout << "y is " << y << endl;
		cout << "z is " << z << endl;

		if(file.eof()) break;

	}

	file.close();

	hist->SetStats(0);

	hist->Draw("COLZ");
	//c->Print("Example.png");

}

```

When I run my script on root, I just get a blank canvas with not even the axis, labels, etc…

> Error: Can’t call TH2D::Fill(x,y,z) in current scope sensortempvsdate.C:51:  
> Possible candidates are…  
> protected: virtual Int\_t TH2::Fill(Double\_t); //MayNotUse  
> protected: virtual Int\_t TH2::Fill(const char\*,Double\_t); //MayNotUse  
> public: virtual Int\_t TH2::Fill(Double\_t x,Double\_t y);  
> public: virtual Int\_t TH2::Fill(Double\_t x,Double\_t y,Double\_t w);  
> public: virtual Int\_t TH2::Fill(Double\_t x,const char\* namey,Double\_t w);  
> public: virtual Int\_t TH2::Fill(const char\* namex,Double\_t y,Double\_t w);  
> public: virtual Int\_t TH2::Fill(const char\* namex,const char\* namey,Double\_t w);  
> public: virtual Int\_t TH1::Fill(Double\_t x);  
> public: virtual Int\_t TH1::Fill(Double\_t x,Double\_t w);  
> public: virtual Int\_t TH1::Fill(const char\* name,Double\_t w);  
> \*\*\* Interpreter error recovered \*\*\*

But I know that the variable type are not wrong b/c it prints them correctly.

> cout \<\< "x is " \<\< x \<\< endl;  
> cout \<\< "y is " \<\< y \<\< endl;  
> cout \<\< "z is " \<\< z \<\< endl;

[avgtemp.txt](https://root-forum.cern.ch/uploads/short-url/dW4U8GECo6qfoq0BfUWBrtC6hkU.txt) (76.5 KB)

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [December 8, 2022, 4:37am UTC](https://root-forum.cern.ch/t/three-column-textfile-th2d/52691/2 "2022-12-08T04:37:59Z")

</div>

If x is a string, then you should do

```auto
		hist->Fill(x.c_str(), y, z);

```

But also, here:

```auto
TH2D *hist = new TH2D("h1", "Temperature Readings", 100, '2022-04-28', '2022-06-30', 100, 30, 61);

```

the ‘2022-04-28’ and ‘2022-06-30’ should not work. For time on axis, check here (or also search this forum for examples on time axis):  
[https://root.cern/doc/master/timeonaxis2\_8C.html](https://root.cern/doc/master/timeonaxis2_8C.html)
