Use of SetTimeFormat

dear all :smiley:

I use a multigraph to plot data, each data is a one day representation. I tried to use SetTimeFormat function to show my data with time but I did not pass. :frowning:
Do you have some idea to do it ?

mg->GetXaxis()->SetTimeDisplay(1);
mg->GetXaxis()->SetTimeFormat("%d 2000-02-28 13:00:01"); ???

Best regards

hubhub

Can you provide a small script showing what “did not pass” ?


Yes of course!

 const Int_t n = nbLignes;
 in.open("scores.txt");
 Double_t  x[n], data[n];
 Int_t  i(0);
 while (1) {

         in >> data[i] ; 
         if (!in.good()) break;
         x[i] = i;
         i++;
  
 }
in.close();


TMultiGraph *mg = new TMultiGraph();
TGraph *gr=new TGraph(n,x,data);
mg->Add(gr);
mg->Draw("ap");
mg->GetXaxis()->SetTimeDisplay(1);
mg->GetXaxis()->SetTimeFormat("%H %d %F2016-03-24 04:30:00");

can you send a script we can execute ?

yes, here it is ! :smiley:

#include <time.h>
#include "TStyle.h"
#include "Riostream.h"
#include "TGraph.h"
#include "TCanvas.h"
#include "TArrow.h"	
#include "TPaveLabel.h"
#include "TGaxis.h"
#include "TPad.h"
#include "TAxis.h"
#include "TLine.h"
#include "TPaveLabel.h"
#include "TEllipse.h"
#include "TText.h"
#include "TMultiGraph.h"
#include "TPaveText.h"
#include "TDatime.h"
#include "TH1F.h"
#include "TGaxis.h"

using namespace std;

int graphAnalyse()
{

 TCanvas *c1 = new TCanvas("c1","c1", 10,10,2000,1600);
 c1->SetGridx();
 c1->SetGridy(); 
 ifstream in;
 in.open("scores.txt");
 Int_t nbLignes(0);
 string ligne; 
 if (in)
 {
	while(getline(in, ligne))
	{
		if (ligne[0] == '#') continue;
		nbLignes++;
	}
 in.close();
 }
 else
 {
	cout << " le fichier n'existe pas " << endl;
 }
 cout << " le nombre de lignes du fichier est " << nbLignes << endl;
 /////////////////////////////////////////////////////////////////////
 const Int_t n = nbLignes;

 in.open("scores.txt"); 
 Double_t  x[n], data[n];
 Int_t  i(0);
 while (1) {
	 
	 in >> data[i] ; 
	 if (!in.good()) break;
	  x[i] = i;
	 i++;
	 
 }
in.close();


TMultiGraph *mg = new TMultiGraph();
TGraph *gr=new TGraph(n,x,data);
gr->SetMarkerStyle(kFullCircle);
mg->Add(gr);
mg->SetMaximum(1000);
mg->SetMinimum(0);
mg->Draw("ap");
mg->GetXaxis()->SetTimeDisplay(1);
mg->GetXaxis()->SetTimeFormat("%H %d %F2016-03-24 04:30:00"); 

gPad->Modified();

return 0;
}

and the score.txt file is

207
295
367
436
485
494
658
1407
766
763
807
785
786

For me it works. You asked to see the hour and day and that’s what you see…

yes, but each data is for one day so I would like to see for example
for my first data 207 => 24
then for 295 => 25
367 => 26

You x value are not date. Look root.cern.ch/how/how-create-axis-time-units
got to the end …

thank it works if I declare each x as time like this
TDatime da1(2016,03,24,15,30,00);
TDatime da2(2016,03,25,15,30,00);
TDatime da3(2016,03,26,15,30,00);
TDatime da4(2016,03,27,15,30,00);
TDatime da5(2016,03,28,15,30,00);

x[0] = da1.Convert();
x[1] = da2.Convert();
x[2] = da3.Convert();
x[3] = da4.Convert();
x[4] = da5.Convert();
x[5] = da6.Convert();
x[6] = da7.Convert();

TGraph *gr=new TGraph(n,x,data);

but I would like to do a loop. :mrgreen:
Is it possible ?

but I would like to do a loop.  :mrgreen: 
Is it possible ?

Yes … just do it … what is the problem ?