# Label points in graph

**URL:** <https://root-forum.cern.ch/t/label-points-in-graph/33841>\
**Category:** Newbie\
**Created:** [April 30, 2019, 9:39pm UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841 "2019-04-30T21:39:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svante](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@Svante](https://root-forum.cern.ch/u/Svante)\
**Post date:** [April 30, 2019, 9:39pm UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/1 "2019-04-30T21:39:13Z")

</div>

Dear all,

I have fitting curve plotted on a canvas and I need to label the points by which the fitting curve pass throw.  
Do you know how to do it in root?  
I have also to label points in a spectrum.

Thank you

---

<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:** [May 2, 2019, 7:11am UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/2 "2019-05-02T07:11:15Z")

</div>

You mean drawing a text near some specific points ?

---

<div class="post-metadata">

**Author:** ![Svante](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@Svante](https://root-forum.cern.ch/u/Svante)\
**Post date:** [May 2, 2019, 7:56am UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/3 "2019-05-02T07:56:06Z")

</div>

yes. This is an example of what I need to do

 ![example](https://root-forum.cern.ch/uploads/default/original/3X/4/7/47ecb2983d1fcc0521e483ee6793e6e4830a61bb.png)

image from google search

---

<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:** [May 2, 2019, 8:00am UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/4 "2019-05-02T08:00:18Z")

</div>

Ok. Do you have a macro drawing your spectrum ? I can try to modify it to do that.

---

<div class="post-metadata">

**Author:** ![zhli](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/e68b1a/32.png) [@zhli](https://root-forum.cern.ch/u/zhli)\
**Post date:** [May 2, 2019, 8:20am UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/5 "2019-05-02T08:20:47Z")

</div>

Please refer to the code listed below.

```cpp
void peaks(TH1F *h)// TH1F *h is your histogram
{
  Double_t *xpeaks=NULL, *ypeaks=NULL;
  TSpectrum s=new TSpectrum(500);
  Int_t nfound=s->Search(h,2,"",0.01); // 0.01 is threshold for peak search.
  TPolyMarker *pm=(TPolyMarker *)
    h->GetListOfFunctions()->FindObject("TPolyMarker");
  pm->SetMarkerStyle(32);
  pm->SetMarkerColor(kGreen);
  pm->SetMarkerSize(0.4);
  xpeaks=s->GetPositionX();
  ypeaks=s->GetPositionY();
  for(int j=0;j<nfound;j++) {
    TLatex *tex=new TLatex(xpeaks[j],ypeaks[j],Form("%.1f",xpeaks[j]));
    tex->SetTextFont(13);
    tex->SetTextSize(14);
    tex->SetTextAlign(12);
    tex->SetTextAngle(90);
    tex->SetTextColor(kRed);
    tex->Draw();
  }
}

```

 ![11](https://root-forum.cern.ch/uploads/default/original/3X/a/2/a201604d984b8c2b51d9dcaca991e333b9d1cc75.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:** [May 2, 2019, 8:35am UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/6 "2019-05-02T08:35:59Z")

</div>

I cannot run your macro … it is incomplete. But what you are doing seems correct. What do you get ?

---

<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:** [May 2, 2019, 8:38am UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/7 "2019-05-02T08:38:12Z")

</div>

Here is a working example.  
[peakstext.C](https://root-forum.cern.ch/uploads/default/original/3X/b/6/b6bcd58da1ac05a5c4bdef877086732e9eea030b.C) (1.2 KB)

---

<div class="post-metadata">

**Author:** ![Svante](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@Svante](https://root-forum.cern.ch/u/Svante)\
**Post date:** [May 2, 2019, 9:00am UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/8 "2019-05-02T09:00:27Z")

</div>

yes running your macro produce the result I wanted thank you so much!

---

<div class="post-metadata">

**Author:** ![zhli](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/e68b1a/32.png) [@zhli](https://root-forum.cern.ch/u/zhli)\
**Post date:** [May 2, 2019, 9:01am UTC](https://root-forum.cern.ch/t/label-points-in-graph/33841/9 "2019-05-02T09:01:14Z")

</div>

I modified the code, it should work.
