# Tlatex location in log scale

**URL:** <https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794>\
**Category:** Newbie\
**Created:** [July 11, 2021, 2:29pm UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794 "2021-07-11T14:29:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keyvan\_Tabaei](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/keyvan_tabaei/32/25908_2.png) [@Keyvan\_Tabaei](https://root-forum.cern.ch/u/Keyvan_Tabaei)\
**Post date:** [July 11, 2021, 2:29pm UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794/1 "2021-07-11T14:29:52Z")

</div>

hi dear experts,

i am trying to draw latex texts on a graph with the y axis log scale.

the text always appears at the top of the graph and when I try to change its location by mouse it goes at the horizontal axis and stuck there.

i tested different location values but the same thing happened.

 ![Screenshot from 2021-07-11 10-22-02](https://root-forum.cern.ch/uploads/default/original/3X/1/e/1e47ddc2a96325d1a942ba9a7083a7ddf9c82d65.png)

> TFile\* f = new TFile(“result.root”);  
> TCanvas\* c1 = new TCanvas(“c1”, “”);
> 
> TH2D\* edepPrimaryH = (TH2D\*)f-\>Get(“2d\_PrimaryedepKernels”);  
> TH2D\* edepFirstH = (TH2D\*)f-\>Get(“2D\_FirstedepKernels”);  
> TH2D\* edepSecondH = (TH2D\*)f-\>Get(“2D\_SecondedepKernels”);  
> TH2D\* edepMultipleH = (TH2D\*)f-\>Get(“2D\_MultipleedepKernels”);  
> TH2D\* edepeBremAnnihilH = (TH2D\*)f-\>Get(“2D\_eBremAnnihiledepKernels”);  
> TH2D\* massH = (TH2D\*)f-\>Get(“2d\_Mass”);
> 
> double ttreedose;  
> double ttreepol;  
> double ttreer;  
> TTree\* \_angle1 = new TTree(“Ntuple1”, “Edep”);  
> \_angle1-\>Branch(“d”, &ttreedose, “d/D”);  
> \_angle1-\>Branch(“p”, &ttreepol, “p/D”);  
> \_angle1-\>Branch(“r”, &ttreer, “r/D”);
> 
> double no\_photon=1e6-3170;  
> double to\_gray=1.609_1e-13;  
> double incident\_e=1.25;  
> double to\_centigray=1e2;  
> double scale=(to\_gray_to\_centigray)/(incident\_e\*no\_photon);
> 
> for(Int\_t iphi=0;iphi\<48;iphi++)  
> for(Int\_t ir=0;ir\<25;ir++)  
> {  
> double edep=edepPrimaryH-\>GetBinContent(iphi,ir)  
> +edepFirstH-\>GetBinContent(iphi,ir)  
> +edepSecondH-\>GetBinContent(iphi,ir)  
> +edepMultipleH-\>GetBinContent(iphi,ir)  
> +edepeBremAnnihilH-\>GetBinContent(iphi,ir);  
> double dose = edep/massH-\>GetBinContent(iphi,ir);  
> isoprimary-\>SetBinContent(iphi,0.5\*(2_ir_ir+1),dose);  
> ttreer=0.5\*(2_ir_ir+1)/10;  
> ttreepol=iphi;  
> ttreedose=dose_scale;  
> \_angle1-\>Fill();  
> }  
> angle1-\>SetLineColor(kBlack);  
> angle1-\>SetLineWidth(2);  
> TMultiGraph \*mg = new TMultiGraph(“mg”, ";r#[]{cm};Dose#timesr^{2}{} #[]{#frac{MeV.cm^{2}{}}{Kg.Photon}}");  
> \_angle1-\>Draw("d_r_r:r",“p==0 && r\<20”,“”);  
> mg-\>Add((TGraph_)gPad-\>GetPrimitive(“Graph”)-\>Clone());  
> \_angle1-\>Draw(“d_r_r:r”,“p==6&&r\<20”,“”);  
> mg-\>Add((TGraph\*)gPad-\>GetPrimitive(“Graph”)-\>Clone());  
> \_angle1-\>Draw(“d_r_r:r”,“p==12&&r\<20”,“”);  
> mg-\>Add((TGraph\*)gPad-\>GetPrimitive(“Graph”)-\>Clone());  
> mg-\>Draw(“AL”);
> 
> gPad-\>SetLogy(1);;  
> TLatex latex;  
> latex.SetTextSize(0.018);  
> latex.SetTextAlign(13); //align at top  
> latex.DrawLatex(5,5,“0^{#circ} - 3.75^{#circ}”);  
> latex.DrawLatex(5,5,“22.5^{#circ} - 26.25^{#circ}”);  
> latex.DrawLatex(5,5,“45^{#circ} - 48.75^{#circ}”);  
> c1-\>cd();  
> c1-\>Update();

how can i draw them?  
many thanks,

---

<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:** [July 11, 2021, 2:56pm UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794/2 "2021-07-11T14:56:05Z")

</div>

Try: `latex.DrawLatexNDC(0.5, 0.5, "blah blah");`

---

<div class="post-metadata">

**Author:** ![Keyvan\_Tabaei](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/keyvan_tabaei/32/25908_2.png) [@Keyvan\_Tabaei](https://root-forum.cern.ch/u/Keyvan_Tabaei)\
**Post date:** [July 11, 2021, 3:36pm UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794/3 "2021-07-11T15:36:54Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> latex.DrawLatexNDC

thank you for your reply,

@couet this is works, but if its location is changed by the mouse (when left-click mouse is released) the latext will disappear I don’t know why this is happening i don’t know it depends on the previous lines or something else.

i can set location values and don’t change it location by mouse however for better positioning and angle i prefer to set its location by mouse.

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [July 13, 2021, 12:51pm UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794/4 "2021-07-13T12:51:21Z")

</div>

Hi @Keyvan_Tabaei,

Unfortunately, @couet is off this week and might take a while for him to reply.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![Keyvan\_Tabaei](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/keyvan_tabaei/32/25908_2.png) [@Keyvan\_Tabaei](https://root-forum.cern.ch/u/Keyvan_Tabaei)\
**Post date:** [July 18, 2021, 4:52pm UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794/5 "2021-07-18T16:52:25Z")

</div>

Hi @jalopezg  
Thank you for your attention,

I used NDC and set position values.  
that was not a crucial problem although it is better to know how we can use Tlatex in log scale while changing its location by mouse is possible.

---

<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:** [July 20, 2021, 8:26am UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794/6 "2021-07-20T08:26:31Z")

</div>

Seems to me it works fine. See that plot. I placed a text at Y = 500:

 ![Screenshot 2021-07-20 at 10.24.16](https://root-forum.cern.ch/uploads/default/original/3X/9/8/9807f803f2a0916ed947284656a487ebd59ba8dc.jpeg)

Now if I go to log scale on Y, I get this plot and the text is still at Y = 500… thats’s what we want.

 ![Screenshot 2021-07-20 at 10.25.56](https://root-forum.cern.ch/uploads/default/original/3X/2/8/28109cf45275078bf6cd86b8800996a8f2df3430.jpeg)

---

<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:** [July 20, 2021, 11:03am UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794/7 "2021-07-20T11:03:14Z")

</div>

The problem description says that, when the canvas is using the “log Y” then:

> [@Keyvan\_Tabaei](#):
>
> if its location is changed by the mouse (when left-click mouse is released) the latext will disappear

---

<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:** [July 20, 2021, 12:18pm UTC](https://root-forum.cern.ch/t/tlatex-location-in-log-scale/45794/8 "2021-07-20T12:18:02Z")

</div>

I just tried. I do not see that with ROOT master. It works fine for me.
