# Error in \<THistPainter::PaintInit\>: log scale requested with a negative argument (-0.141557)

**URL:** <https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757>\
**Category:** Newbie\
**Tags:** root\
**Created:** [June 19, 2025, 7:47am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757 "2025-06-19T07:47:59Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 19, 2025, 7:48am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/1 "2025-06-19T07:48:00Z")

</div>

Dear experts

I want to calculate the time cost for two different algorithms for convolution, then I draw them on a `TMultiGraph` which contains 2 `TGraph` inside. I confirmed every point is positive x and y, but I got the error when I try to `TCanvas::SetLogx()` and `TCanvas::SetLogy()`, why?

I attach my working example here:  
[checkTimeCostFFT.cxx](https://root-forum.cern.ch/uploads/short-url/xxZNeA3s3HVZFM8EfXkzpDzJBmG.cxx) (4.7 KB)  
[graph.root](https://root-forum.cern.ch/uploads/short-url/l7YFqqadRFgSblqKU6knWSMvkU0.root) (6.9 KB)

And the output of values says they are all positive:

```auto
0th loop finished with inputLength = 1
    normal convolution time cost: 2.625e-06
    FFT convolution time cost: 0.391761
1th loop finished with inputLength = 4
    normal convolution time cost: 9.417e-06
    FFT convolution time cost: 0.662822
2th loop finished with inputLength = 16
    normal convolution time cost: 6.8792e-05
    FFT convolution time cost: 1.12083
3th loop finished with inputLength = 64
    normal convolution time cost: 0.000505083
    FFT convolution time cost: 1.80859
4th loop finished with inputLength = 256
    normal convolution time cost: 0.00397829
    FFT convolution time cost: 2.83119

```

ROOT version: 6.32.08

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 19, 2025, 7:53am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/2 "2025-06-19T07:53:36Z")

</div>

I’ll check

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 19, 2025, 8:04am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/3 "2025-06-19T08:04:40Z")

</div>

I am missing the file `graph.root`.

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 19, 2025, 11:07pm UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/4 "2025-06-19T23:07:20Z")

</div>

Oh, sorry for that, now I uploaded the `graph.root`

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 20, 2025, 2:56am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/5 "2025-06-20T02:56:13Z")

</div>

And I confirmed that this error is from `SetLogy()`, not `SetLogx()`

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 20, 2025, 12:17pm UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/6 "2025-06-20T12:17:20Z")

</div>

The painting method of TMultigraph keeps a margin of 0.0001 of the y range to avoid the graphs’ points overlap the Y axis. In your case this value is too big and the minimum of the axis becomes negative. You can bypass this problem with some code like:

```auto
    TMultiGraph* g_time = new TMultiGraph();
    g_time->Add(g_normal);
    g_time->Add(g_FFT);
    
    g_time->GetXaxis()->SetTitle("Input vector length");
    g_time->GetYaxis()->SetTitle("Time cost [s]");
    printf("g_time minimum = %g\n",g_time->GetHistogram()->GetMinimum()); // shows the axis minimum is < 0
    g_time->SetMinimum(0.000001); // define a positive minimum
    c->SetLogx();
    c->SetLogy();

    g_time->Draw("AP")

```

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 20, 2025, 3:39pm UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/7 "2025-06-20T15:39:32Z")

</div>

Thank you, this fixed the problem, but I found if I change the loop to 10 then only the last 4 points are shown, can you please have a look?  
[checkTimeCostFFT.cxx](https://root-forum.cern.ch/uploads/short-url/5PQ1Z9a5zzULm04Tzu9O5n7cH2y.cxx) (5.0 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 23, 2025, 7:12am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/8 "2025-06-23T07:12:41Z")

</div>

I am looking at it

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 23, 2025, 7:34am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/9 "2025-06-23T07:34:25Z")

</div>

Actually the points are there you will see them if you suppress the log scale along X. I think we are facing the same issue we saw with log Y . All your values along X and Y are positive so the alogorithm computing the limit should be able to generate proper positive scales automalically. Give me a bit of time and I’ll comme with a fix.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 23, 2025, 9:05am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/10 "2025-06-23T09:05:58Z")

</div>

At the end of you macro I printed the two graphs and made a simpler macro with these values. I thought I will get the same errors but surpreingly I get a correct plot even without setting the Y minium. The macro is the following. May be you can try it.

```auto
{
   auto g1 = new TGraph();
   g1->SetMarkerStyle(20);
   g1->SetMarkerColor(kBlue);
   g1->AddPoint( 1, 3e-06);
   g1->AddPoint( 4, 7.25e-06);
   g1->AddPoint( 16, 5.6458e-05);
   g1->AddPoint( 64, 0.000358042);
   g1->AddPoint( 256, 0.00288179);
   g1->AddPoint( 1024, 0.0232125);
   g1->AddPoint( 4096, 0.181971);
   g1->AddPoint( 16384, 1.47276);
   g1->AddPoint( 65536, 23.9272);
   g1->AddPoint( 262144, 393.396);
   
   auto g2 = new TGraph();
   g2->SetMarkerStyle(21);
   g2->SetMarkerColor(kRed);
   g2->AddPoint( 1, 0.310709);
   g2->AddPoint( 4, 0.534144);
   g2->AddPoint( 16, 0.892891);
   g2->AddPoint( 64, 1.45679);
   g2->AddPoint( 256, 2.29943);
   g2->AddPoint( 1024, 3.49948);
   g2->AddPoint( 4096, 5.42755);
   g2->AddPoint( 16384, 11.2071);
   g2->AddPoint( 65536, 20.767);
   g2->AddPoint( 262144, 35.4994);
   
   auto c = new TCanvas();
   c->SetLogx();
   c->SetLogy();
   auto gm = new TMultiGraph();
   gm->Add(g1);
   gm->Add(g2);
   gm->Draw("AP");
}

```

So it seems there is more than simply the grpahics part of root involved.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 23, 2025, 9:34am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/11 "2025-06-23T09:34:38Z")

</div>

I found the culprit. If, in my previous example you, do:

```auto
   auto c = new TCanvas();
   auto gm = new TMultiGraph();
   gm->GetXaxis()->SetTitle("Input vector length");
   gm->GetYaxis()->SetTitle("Time cost [s]");
   c->SetLogx();
   c->SetLogy();
   gm->Add(g1);
   gm->Add(g2);
   gm->Draw("AP");

```

then it cashes like in you example.  
But if you set the titles after the 2 “Add” then it works.

```auto
   auto gm = new TMultiGraph();
   c->SetLogx();
   c->SetLogy();
   gm->Add(g1);
   gm->Add(g2);
   gm->GetXaxis()->SetTitle("Input vector length");
   gm->GetYaxis()->SetTitle("Time cost [s]");
   gm->Draw("AP");

```

It is because when you set the titles `GetHistogram` is called which creates the internal histogram `fHistogram` which hold the axis. But the real limits cannot be computed correctly as the Multigraph has no data yet. I will investigate how this can be improved.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 23, 2025, 10:59am UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/12 "2025-06-23T10:59:12Z")

</div>

Indeed [the documentation](https://root.cern/doc/master/classTMultiGraph.html#afc6700fbae200601558e164468e9890e) of TMultiGraph::GetXaxis (and GetYaxis), already mentionned that.

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 30, 2025, 1:44pm UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/13 "2025-06-30T13:44:45Z")

</div>

This works for me, thanks a lot!

Indeed this is described in the class documentation, but setting titles before graph been drawn works if I used `TGraph`, so I expected it also work in `TMultiGraph`…

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 30, 2025, 2:50pm UTC](https://root-forum.cern.ch/t/error-in-thistpainter-paintinit-log-scale-requested-with-a-negative-argument-0-141557/63757/14 "2025-06-30T14:50:17Z")

</div>

TMultigraph is a collection of TGraph. The number of TGraphs in a TMultigraph is not limited. You can add as many as you want. Therefore the axis of a TMultigraph can be computed only at painting time, and are not defined before that.
