# Change Polymarkers position in histogram

**URL:** <https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [August 19, 2021, 9:51am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349 "2021-08-19T09:51:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilomidze](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilomidze](https://root-forum.cern.ch/u/ilomidze)\
**Post date:** [August 19, 2021, 9:51am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/1 "2021-08-19T09:51:19Z")

</div>

\_ROOT Version: 6.22/08  
\_Platform: macosx64  
_Compiler:_ Not Provided

I have a histogram TH1D \* h.  
It has polymarker on some position. I want to change that position.  
Any suggestions/help?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 19, 2021, 10:01am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/2 "2021-08-19T10:01:40Z")

</div>

Try: `h->GetListOfFunctions()->Print();`

---

<div class="post-metadata">

**Author:** ![ilomidze](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilomidze](https://root-forum.cern.ch/u/ilomidze)\
**Post date:** [August 19, 2021, 10:12am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/3 "2021-08-19T10:12:14Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> -\>Print()

Thank you for the reply.  
I was not able to get the result I was hoping for…

I get This:

```auto
Collection name='TList', class='TList', size=2
 TPaletteAxis X1=2060.800000 Y1=0.000000 X2=2176.000002 Y2=1024.000000 FillColor=1178 FillStyle=1001
 TPaveStats X1=1740.800052 Y1=761.600014 X2=2252.800067 Y2=1068.800011 FillStyle=1001
 Collection name='TList', class='TList', size=6
  Text X=0.000000 Y=0.000000 Text=AmpAmp_Mod1_ch01 Font=0 Size=0.036800 Color=0 Align=0
  Text X=0.000000 Y=0.000000 Text=Entries = 290257 Font=0 Size=0.000000 Color=0 Align=0
  Text X=0.000000 Y=0.000000 Text=Mean x = 267.5 Font=0 Size=0.000000 Color=0 Align=0
  Text X=0.000000 Y=0.000000 Text=Mean y = 114.5 Font=0 Size=0.000000 Color=0 Align=0
  Text X=0.000000 Y=0.000000 Text=Std Dev x = 37.06 Font=0 Size=0.000000 Color=0 Align=0
  Text X=0.000000 Y=0.000000 Text=Std Dev y = 53.29 Font=0 Size=0.000000 Color=0 Align=0

```

---

<div class="post-metadata">

**Author:** ![ilomidze](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilomidze](https://root-forum.cern.ch/u/ilomidze)\
**Post date:** [August 19, 2021, 10:26am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/4 "2021-08-19T10:26:38Z")

</div>

This is how the polymarker is being added…

```auto
  double pmX [1] = {(double)maxXcoord}; 
  double pmY [1] = {(double)maxVal};
  int pmSize = 1;
  TPolyMarker *pm = new TPolyMarker(pmSize, pmX, pmY);
  h->GetListOfFunctions()->Add(pm);
  pm->SetMarkerStyle(23);
  pm->SetMarkerColor(kRed);
  pm->SetMarkerSize(1.3);

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 19, 2021, 10:28am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/5 "2021-08-19T10:28:00Z")

</div>

So, you need to modify “`pmX[...]`” and “`pmY[...]`” values as you want.

BTW. For a single marker, it is better to use a simple [TMarker](https://root.cern/doc/master/classTMarker.html) object.

---

<div class="post-metadata">

**Author:** ![ilomidze](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilomidze](https://root-forum.cern.ch/u/ilomidze)\
**Post date:** [August 19, 2021, 10:36am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/6 "2021-08-19T10:36:58Z")

</div>

good advice on TMarker

About modifying pmX and pmY:  
I want to change marker position after it was placed.  
To explain better: I’m giving the user option (via TButton) to move marker “left” or “right” if he/she thinks it’s on a wrong place.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 19, 2021, 10:40am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/7 "2021-08-19T10:40:31Z")

</div>

You will need to “retrieve” a pointer to the drawn [TPolyMarker](https://root.cern/doc/master/classTPolyMarker.html) object and use its [TPolyMarker::GetX](https://root.cern/doc/master/classTPolyMarker.html#ac99fdc82c58991ff368d04e57b7d5415) and / or [TPolyMarker::GetY](https://root.cern/doc/master/classTPolyMarker.html#a3a4810643f7a102c0533ea9362e1538e) methods to modify their values.

---

<div class="post-metadata">

**Author:** ![ilomidze](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilomidze](https://root-forum.cern.ch/u/ilomidze)\
**Post date:** [August 19, 2021, 11:22am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/8 "2021-08-19T11:22:50Z")

</div>

Unfortunately, its hard to get from the documentation…

Can you write an example like you did before?  
Similar to

```auto
h->GetListOfFunctions()->Print();

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 19, 2021, 2:38pm UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/9 "2021-08-19T14:38:06Z")

</div>

```cpp
{
  TH1D *h = new TH1D("h", "h", 100, 0., 1);
  h->GetListOfFunctions()->Print();
  //
  double pmX [2] = {0.1, 0.2};
  double pmY [2] = {0.3, 0.4};
  int pmSize = 2;
  TPolyMarker *pm = new TPolyMarker(pmSize, pmX, pmY);
  pm->SetMarkerStyle(23);
  pm->SetMarkerColor(kRed);
  pm->SetMarkerSize(1.3);
  h->GetListOfFunctions()->Add(pm);
  h->GetListOfFunctions()->Print();
  //
  h->Draw();
  //
  TPolyMarker *p =
    ((TPolyMarker*)(h->GetListOfFunctions()->FindObject("TPolyMarker")));
  if (p) {
    p->GetX()[0] += 0.5; // shift "x" of the first marker
    p->GetY()[0] -= 0.2; // shift "y" of the first marker
    if (gPad) { gPad->Modified(); gPad->Update(); }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ilomidze](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilomidze](https://root-forum.cern.ch/u/ilomidze)\
**Post date:** [August 19, 2021, 3:42pm UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/10 "2021-08-19T15:42:34Z")

</div>

Thank you so much - it works!!

---

<div class="post-metadata">

**Author:** ![Benedict1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@Benedict1](https://root-forum.cern.ch/u/Benedict1)\
**Post date:** [August 31, 2021, 4:09am UTC](https://root-forum.cern.ch/t/change-polymarkers-position-in-histogram/46349/12 "2021-08-31T04:09:51Z")

</div>

Thanks for the information keep sharing such informative post keep suggesting such post.
