# Error bars drawn in wrong place if SetLogx

**URL:** <https://root-forum.cern.ch/t/error-bars-drawn-in-wrong-place-if-setlogx/37507>\
**Category:** ROOT\
**Tags:** graphics, bug, hist\
**Created:** [January 9, 2020, 7:52pm UTC](https://root-forum.cern.ch/t/error-bars-drawn-in-wrong-place-if-setlogx/37507 "2020-01-09T19:52:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [January 9, 2020, 7:52pm UTC](https://root-forum.cern.ch/t/error-bars-drawn-in-wrong-place-if-setlogx/37507/1 "2020-01-09T19:52:38Z")

</div>

`THistPainter` draws error bars in the wrong place on a pad with `SetLogx`. Reproducer follows.

* * *

```python
import ROOT
can = ROOT.TCanvas()
can.SetLogx()

h = ROOT.TH1D('h', 'h', 5, 1, 6)
for i in xrange(1, 6):
    h.SetBinContent(i, i)
h.Draw()
can.Update() # notice that it looks fine
h.Sumw2()
h.Draw()
can.Update() # notice that the histogram disappears

h2 = ROOT.TH1D('h2', 'h2', 5, 0, 5) # now make a histogram with a bin at 0
for i in xrange(1, 6):
    h2.SetBinContent(i, i)
h2.Draw()
can.Update() # notice that it looks fine
h2.Sumw2()
h2.Draw()
can.Update() # notice that one bin disappears and the lower limits of each bin extend too low
h2.Draw('h')
can.Update() # notice that the histogram now appears in the right place with only the error bars in the wrong

```

* * *

_ROOT Version:_ master  
_Platform:_ macOS  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [January 10, 2020, 7:28pm UTC](https://root-forum.cern.ch/t/error-bars-drawn-in-wrong-place-if-setlogx/37507/3 "2020-01-10T19:28:45Z")

</div>

Okay, I was able to track down the source of the problem. `THistPainter::PaintErrors` failed to adjust for the log scale when calculating the location of the error bars. I have created a [JIRA task](https://sft.its.cern.ch/jira/browse/ROOT-10505) and submitted a [pull request](https://github.com/root-project/root/pull/4755) fixing the issue.

---

<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:** [January 13, 2020, 10:14am UTC](https://root-forum.cern.ch/t/error-bars-drawn-in-wrong-place-if-setlogx/37507/5 "2020-01-13T10:14:05Z")

</div>

The following (simpler ) macro is enough to show the problem.

```auto
void graphlogx() {
   auto can = new TCanvas();
   can->SetLogx();
   auto h2 = new TH1D("h2", "h2", 5, 0, 5);
   for (int i=1; i<6; i++) h2->SetBinContent(i, i);
   h2->Sumw2();
   h2->Draw();
   h2->Draw("hist same");
}

```

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [January 13, 2020, 12:14pm UTC](https://root-forum.cern.ch/t/error-bars-drawn-in-wrong-place-if-setlogx/37507/6 "2020-01-13T12:14:17Z")

</div>

Yes, thank you, that’s much less meandering than my script above.

---

<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:** [January 13, 2020, 12:16pm UTC](https://root-forum.cern.ch/t/error-bars-drawn-in-wrong-place-if-setlogx/37507/7 "2020-01-13T12:16:13Z")

</div>

I applied this patch. Thanks to @mwilkins to have providing it. It is correct. I wonder why this has not been seen earlier … ☹

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [January 27, 2020, 12:16pm UTC](https://root-forum.cern.ch/t/error-bars-drawn-in-wrong-place-if-setlogx/37507/8 "2020-01-27T12:16:13Z")

</div>

Closed on January 27, 2020, 12:16pm UTC

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