TGraph Range when using Log Axis

Hi,

I’ve noticed when using a TGraph spanning many orders of magnitude that the zoom for the output depends on the order of setting the log-axis. If one sets the x-axis to log first the y-axis values are truncated to three orders of magnitude. While setting the y-axis to log first displays the entire range of data. This is displayed below:

Below is the script that produced the above plot:

{
   const int numPoints = 10;
   double xValues[numPoints], yValues[numPoints];
   for (int i=0;i<numPoints;i++) {
      xValues[i] = i+2;
      yValues[i] = pow(10,i-3);
   }
   TGraph *g1 = new TGraph(numPoints, xValues, yValues);
   TGraph *g2 = new TGraph(numPoints, xValues, yValues);

   TCanvas *c = new TCanvas("c","C");
   c->DivideSquare(2);

   //Log x first
   c->cd(1);
   g1->Draw();
   gPad->SetLogx();
   c->Update();
   gPad->SetLogy();

   //Log y first
   c->cd(2);
   g2->Draw();
   gPad->SetLogy();
   c->Update();
   gPad->SetLogx();
}

This was observed with ROOT 6.08/06.

I see the same thing with the ROOT master. Surely a different path is taken in both cases. ROOT attempt to set the Log scale on plot having a Y value Thanks to have reported this problem. A workaround is:

   TGraph *g1 = new TGraph(numPoints, xValues, yValues);
   g1->GetHistogram()->SetMinimum(0.001);
   TGraph *g2 = new TGraph(numPoints, xValues, yValues);
   g1->GetHistogram()->SetMinimum(0.001);

Your workaround works as long as the minimum is greater than zero. The following also appeared to work:

g1->SetMinimum(0.001);

Yes … no need to specify the intermediate histogram.

If the minimum is negative the Log scale along Y will be invalid anyway and ROOT will try to find a suitable minimal value as long as the maximum is positive. If the maximum is negative also ROOT will complain that it cannot display the graph.

Agreed. Thanks for clarifying for other who might find this thread.

Will there be some effort to resolve the issue with the automatic determination of the limits?

I think this issue should be fixed. The order off setting the log scale should not have any effect on the display. Can you submit a bug report in Jira ?

I will give it a try.

https://sft.its.cern.ch/jira/secure/Dashboard.jspa
I can do it for you if you do not manage. Let me know.

I had no issue: https://sft.its.cern.ch/jira/browse/ROOT-8751

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.