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…
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.
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.
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 ?