# Error bars inside markers with draw("same")

**URL:** <https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631>\
**Category:** ROOT\
**Tags:** graphics\
**Created:** [August 27, 2024, 3:41pm UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631 "2024-08-27T15:41:00Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tristan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tristan/32/36486_2.png) [@Tristan](https://root-forum.cern.ch/u/Tristan)\
**Post date:** [August 27, 2024, 3:41pm UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/1 "2024-08-27T15:41:01Z")

</div>

Hi,

I discovered that when plotting a TGraphErrors with error bars smaller than the markers, the bars are now displayed over the marker, pointing inward. I assume it’s a new feature dating back from release 6.26, given what I could guess from the release notes. That’s a very nice one, by the way.  
However I noticed that these bars do not appear if a second graph is drawn. If the error bars are increase by hand so that they become larger than the markers, then they appear on both graphs.  
Here is a minimal working environment to confirm this:

```auto
#include "TGraphErrors.h"
#include "TCanvas.h"

int main() {

    const int nPoints = 10;
    double x[nPoints] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    double y2[nPoints] = {1.5, 2.5, 2, 3.5, 3, 4, 4.5, 5.5, 5, 5.5};
    double y1[nPoints] = {1, 2, 1.5, 3, 2.5, 3.5, 4, 5, 4.5, 6};
    double ex[nPoints] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    double eyy = 0.02;
    double ey[nPoints] = {eyy, eyy, eyy, eyy, eyy, eyy, eyy, eyy, eyy};

    TGraphErrors *graph1 = new TGraphErrors(nPoints, x, y1, ex, ey);
    TGraphErrors *graph2 = new TGraphErrors(nPoints, x, y2, ex, ey);

    TCanvas *canvas = new TCanvas("canvas", "TGraphErrors Example", 1600, 1200);

    graph1->SetMarkerStyle(20);
    graph1->SetMarkerColor(kRed);
    graph1->SetMarkerSize(5);
    graph1->SetLineWidth(3);
    graph1->SetTitle(Form("TGraphErrors with errors bars of %.2f", eyy));

    graph2->SetMarkerStyle(20);
    graph2->SetMarkerColor(kBlue);
    graph2->SetMarkerSize(5);
    graph2->SetLineWidth(3);

    graph1->Draw("AP"); 
    graph2->Draw("P SAME");

    canvas->SaveAs(Form("MWE_error_bars_%.2f.png", eyy));
}

```

and here are 2 versions of the output plot obtained for vertical error bars of 0.02 and 0.2:

 ![MWE_error_bars_0.02](https://root-forum.cern.ch/uploads/default/original/3X/6/4/64eba4d69b33d11e63992cdf11a205af1735dbaa.png)  
 ![MWE_error_bars_0.20](https://root-forum.cern.ch/uploads/default/original/3X/a/5/a5bca3babaacf36c0a735f86e2256d2e9ed4be4b.png)

Could this be a bug? Maybe the new feature has not been implemented “recursively” so that it can work nicely with the “same” option for draw().

Cheers,  
Tristan

* * *

_ROOT Version:_ 6.32.02

* * *

---

<div class="post-metadata">

**Author:** ![mdessole](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mdessole/32/34021_2.png) [@mdessole](https://root-forum.cern.ch/u/mdessole)\
**Post date:** [August 27, 2024, 3:59pm UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/2 "2024-08-27T15:59:45Z")

</div>

Hello @Tristan,  
thank you for reporting this, I add in the loop our graphics expert @couet!  
Cheers,  
Monica

---

<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:** [August 28, 2024, 8:06am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/3 "2024-08-28T08:06:28Z")

</div>

I get the same result. I will 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:** [August 28, 2024, 8:18am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/4 "2024-08-28T08:18:14Z")

</div>

Ok, understood. I tried this:

```auto
{
    const int nPoints = 10;
    double x[nPoints] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    double y1[nPoints] = {1, 2, 1.5, 3, 2.5, 3.5, 4, 5, 4.5, 6};
    double ex[nPoints] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    double eyy = 0.02;
    double ey[nPoints] = {eyy, eyy, eyy, eyy, eyy, eyy, eyy, eyy, eyy};
    auto graph1 = new TGraphErrors(nPoints, x, y1, ex, ey);
    graph1->Draw("AP");
}

```

whixh draws your graph wihout any marker. I get this:

 ![Screenshot 2024-08-28 at 10.17.08](https://root-forum.cern.ch/uploads/default/original/3X/5/5/552aa7f148ffe20b5a8ba36c545850ca371a3b60.png)  
The errors bars are so small that any marker excpt a simple dot will fit in it.

---

<div class="post-metadata">

**Author:** ![Tristan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tristan/32/36486_2.png) [@Tristan](https://root-forum.cern.ch/u/Tristan)\
**Post date:** [September 3, 2024, 10:10am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/5 "2024-09-03T10:10:41Z")

</div>

Hello Couet and thank you for your answer. However I don’t get your point, I’m sorry. I know the errors are smaller than the marker and this is what I pointed out. The thing is that the first TGraphErrors draws the errors within the marker, on top of it, while the second, drawn with the “same option”, doesn’t even though it’s a circle marker as well.

Cheers,  
Tristan

---

<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:** [September 3, 2024, 11:43am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/7 "2024-09-03T11:43:34Z")

</div>

Yes, you are correct. When `graph1` is drawn with the option `"AP"`, it should not display the error bars. It works correctly when the option `"A"` is not included. I will debug. The minimal reproducer is:

```auto
{
   const int n = 2;
   double x[n] = {1, 10};
   double y[n] = {1.0, 3.0};
   double ex[n] = {0, 0};
   double ey[n] = {0.02, 0.02};
   
   auto g = new TGraphErrors(n, x, y, ex, ey);
   
   g->SetMarkerStyle(20);
   g->SetMarkerColor(kRed);
   g->SetMarkerSize(5);
   g->SetLineWidth(3);
   
   g->Draw("AP");
}

```

---

<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:** [September 3, 2024, 12:28pm UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/8 "2024-09-03T12:28:46Z")

</div>

Indeed the real minimal reproducer is:

```auto
{
   auto C = new TCanvas();
   C->DrawFrame(0., 0., 10, 10);

   auto g1 = new TGraphErrors();
   g1->AddPointError(5,5,0,0.02);
   g1->SetMarkerStyle(24);
   g1->SetMarkerSize(9);
   g1->Draw("P");
}

```

 ![Screenshot 2024-09-03 at 14.28.07](https://root-forum.cern.ch/uploads/default/original/3X/3/e/3efc5a8ee96337a8532064db8ef3bd56861de205.png)

---

<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:** [September 4, 2024, 9:19am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/9 "2024-09-04T09:19:08Z")

</div>

The complete test should be done with:

```auto
{
   auto C = new TCanvas();
   C->DrawFrame(0., 0., 10, 10);

   auto g1a = new TGraphErrors();
   g1a->AddPointError(2,7,0.3,0.3);
   g1a->SetMarkerStyle(24);
   g1a->SetMarkerSize(9);
   g1a->Draw("P");

   auto g1b = new TGraphErrors();
   g1b->AddPointError(2,3,0.3,0.3);
   g1b->SetMarkerStyle(24);
   g1b->SetMarkerSize(9);
   g1b->Draw(">P");

   auto g2a = new TGraphAsymmErrors();
   g2a->AddPointError(5,7,0.2,0.3,0.2,0.3);
   g2a->SetMarkerStyle(24);
   g2a->SetMarkerSize(9);
   g2a->Draw("P");

   auto g2b = new TGraphAsymmErrors();
   g2b->AddPointError(5,3,0.2,0.3,0.2,0.3);
   g2b->SetMarkerStyle(24);
   g2b->SetMarkerSize(9);
   g2b->Draw(">P");

   auto g3a = new TGraphBentErrors();
   g3a->AddPointError(8,7,0.2,0.3,0.2,0.3);
   g3a->SetMarkerStyle(24);
   g3a->SetMarkerSize(9);
   g3a->Draw("P");

   auto g3b = new TGraphBentErrors();
   g3b->AddPointError(8,3,0.2,0.3,0.2,0.3);
   g3b->SetMarkerStyle(24);
   g3b->SetMarkerSize(9);
   g3b->Draw(">P");
}

```

---

<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:** [September 4, 2024, 9:40am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/10 "2024-09-04T09:40:38Z")

</div>

This PR (under construction) fixes the problem: [Do not draw error bars when they are smaller than the marker. by couet · Pull Request #16372 · root-project/root · GitHub](https://github.com/root-project/root/pull/16372)

---

<div class="post-metadata">

**Author:** ![Tristan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tristan/32/36486_2.png) [@Tristan](https://root-forum.cern.ch/u/Tristan)\
**Post date:** [September 5, 2024, 1:37pm UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/11 "2024-09-05T13:37:55Z")

</div>

Hi,

In my opinion, the behaviour observed for the first TGraphErrors, with the error bars drawn inwards, is a very good and convenient feature, whether it was added on purpose or not. Maybe it would be best to propagate this behaviour to all TGraphErrors drawn after the first one instead of suppressing it?

Cheers,  
Tristan

---

<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:** [September 6, 2024, 6:54am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/12 "2024-09-06T06:54:20Z")

</div>

It seems to me that error bars being drawn inwards is not a desired feature. The scenario where the marker is larger than the error bars wasn’t considered in the `TGraphPainter` code. The meaning of such “inward error bars” is confusing. In your example, you used solid markers, and depending on whether the axes are present, the markers are drawn either before or after the error bars. That’s why, in your first plot, the error bars aren’t visible on the blue marker. In my additional examples, I used hollow markers, and we can clearly see that, in case of markers larger than the errors, the error bars are drawn inwards in all cases (with or without predefined axes).

Drawing the error bars inward inside the marker, makes the plot confusing, as error bars are typically meant to represent uncertainty or variation, and drawing them inward could distort this interpretation.

---

<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:** [September 9, 2024, 9:09am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/13 "2024-09-09T09:09:02Z")

</div>

The PR is merged. [Do not draw error bars when they are smaller than the marker. by couet · Pull Request #16372 · root-project/root · GitHub](https://github.com/root-project/root/pull/16372#event-14179823545)

---

<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:** [September 23, 2024, 9:09am UTC](https://root-forum.cern.ch/t/error-bars-inside-markers-with-draw-same/60631/14 "2024-09-23T09:09:16Z")

</div>

Closed on September 23, 2024, 9:09am UTC

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