Change Polymarkers position in histogram

_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?

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

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

I get This:

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

This is how the polymarker is being added…

  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);

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 object.

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.

You will need to “retrieve” a pointer to the drawn TPolyMarker object and use its TPolyMarker::GetX and / or TPolyMarker::GetY methods to modify their values.

Unfortunately, its hard to get from the documentation…

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

h->GetListOfFunctions()->Print();
{
  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(); }
  }
}
1 Like

Thank you so much - it works!!

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