Axis loses the time format

Dear all,

I am trying to have a timescale axis in a TGraph and, as many people, I have some difficulties getting what I want.
My main problem is that the axis seems to “forget” the time format after I set points in the TGraph.

Here is an example:

// Create the TGraph and set the properties I want for the axis
TGraph tg;
tg->SetMarkerStyle(3);
tg->GetXaxis()->SetTimeDisplay(1);
tg->GetXaxis()->SetNdivisions(-503);
tg->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M");
// Set the global offset to NOW
TDatime da;
gStyle->SetTimeOffset(da.Convert());
// Draw the TGraph (here we have the time axis)
tg->Set(10)
tg->Draw("ap")
// Add a point 
TDatime now;
tg->SetPoint(0, now.Convert(), 3);
gPad->Modified();
// now the axis is not in time scale anymore...

Why do I lose the time scale ?
Should set again after each new point the properties of the axis ?

By the way, why do I have an extra marker at 0,0 right after the first drawing ? I haven’t set a point yet…

Thanks a lot for your help
Barth

here is a working example:

{
   TDatime da1(2008,02,28,15,52,00);
   TDatime da2(2008,02,28,15,53,00);

   double x[2],y[2];

   y[0] = 1.;
   y[1] = 2.;
   x[0] = da1.Convert();
   x[1] = da2.Convert();

   TGraph mgr(2,x,y);
   mgr.SetMarkerStyle(20);

   mgr.Draw("ap");

   mgr.GetXaxis()->SetTimeDisplay(1);
   mgr.GetXaxis()->SetNdivisions(-503);
   mgr.GetXaxis()->SetTimeFormat("%H:%M:%S");
   mgr.GetXaxis()->SetTimeOffset(0,"gmt");
}

Hi,

I know this example. However, in my program the TGraph is updated every minute by adding a new point, and I can see that the axis is losing its properties. This is why I have posted a different example showing the problem.

Imagine the following task: Create a TGraph, X axis in time scale with a minimum at TGraph building time and a maximum at about the time of the latest added point , add a point to it every 5 seconds or so.

How would you do this ?
As far as I can see, I have to re-apply the properties of the axis every time I add a point.

Cheers,
Barth

In fact when you use GetAxis on a TGraph you get the axis of the undelaying histogram. See:
root.cern.ch/root/html/src/TGrap … tml#kqKKVD
So the histogram is recreated each time you change the graph.
May be you can create an histogram with time axis, and each time you change the TGraph you also do SetHistogram… I will try on my side.

Hi,

Ok, right, I understand.
It is ok for me to re-apply the axis’ properties each time I add a point.

As mentionned in my first post, I am also surprised by the point that appears at 0,0 before I add any point to the TGraph. How can I get rid of it ? Should I simply do a Set(0) right after the TGraph creation ?

Thank you very much for your help,
Barth

The Set is not needed… just add points.

If I don’t do Set(0), I have an extra point at 0,0. I don’t want this point :slight_smile:

Barth

do not use Set:

{
TGraph *tg = new TGraph();;
tg->SetMarkerStyle(20);
tg->Draw("ap");
tg->SetPoint(0, 0, 3);
}