# TPolyLine outside of 2DHistogram

**URL:** <https://root-forum.cern.ch/t/tpolyline-outside-of-2dhistogram/50844>\
**Category:** Newbie\
**Created:** [July 18, 2022, 12:02pm UTC](https://root-forum.cern.ch/t/tpolyline-outside-of-2dhistogram/50844 "2022-07-18T12:02:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gec](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@Gec](https://root-forum.cern.ch/u/Gec)\
**Post date:** [July 18, 2022, 12:02pm UTC](https://root-forum.cern.ch/t/tpolyline-outside-of-2dhistogram/50844/1 "2022-07-18T12:02:41Z")

</div>

How to prevent TPolyLine appearing outside of the Histogram? Some dots which define TPolyLine are outside of the 2DHistograms dimensions so it is shown on all available Canvas area , but I only want that part of the colored TPolyLine which is inside of the 2DHistogram to be shown.

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [July 18, 2022, 1:30pm UTC](https://root-forum.cern.ch/t/tpolyline-outside-of-2dhistogram/50844/2 "2022-07-18T13:30:32Z")

</div>

Hi @Gec,

thanks for asking! I think this question can be answered best by @couet, whom I invite to take a look at this thread.

In any case, can you please attach a script to show your problem such that he can help more efficiently? Otherwise I’m afraid it will not be possible to help.

Thanks!

---

<div class="post-metadata">

**Author:** ![Gec](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@Gec](https://root-forum.cern.ch/u/Gec)\
**Post date:** [July 20, 2022, 2:23pm UTC](https://root-forum.cern.ch/t/tpolyline-outside-of-2dhistogram/50844/3 "2022-07-20T14:23:03Z")

</div>

Hello @jonas  
Thank you for your answer.

This is part of code concerning plot of PolyLine:

```
  TGraph *min = new TGraph();
  min->SetPoint(0,truth_PVx,truth_PVy);
  min->SetMarkerStyle(29);
  min->SetMarkerColor(kRed);
  min->Draw("Psame");
  
  Double_t dx = 0.2; Double_t dy = 0.2;
  Int_t ncolors = gStyle->GetNumberOfColors();
  Double_t x[4],y[4];
  float phi = jet_phi_orig->at(index_max_truthpt);
  
  cout<<"Jet truth phi orig: "<<phi<<endl; 

  x[0] = truth_PVx; y[0] = truth_PVy;
  x[1] = x[0] + 500.*cos(phi+0.4); y[1] = y[0] + 500.*sin(phi+0.4);
  x[2] = x[0] + 500.*cos(phi-0.4); y[2] = y[0] + 500.*sin(phi-0.4);
  x[3] = x[0]; y[3] = y[0];
  TPolyLine *pl = new TPolyLine(4,x,y);
  pl->SetFillColorAlpha(7, 0.571);
  pl->Draw("f");
  
  x[0] = truth_PVx; y[0] = truth_PVy;
  x[1] = x[0] + 50.*cos(phi+0.3); y[1] = y[0] + 50.*sin(phi+0.3);
  x[2] = x[0] + 50.*cos(phi-0.3); y[2] = y[0] + 50.*sin(phi-0.3);
  x[3] = x[0]; y[3] = y[0];
  TPolyLine *pl_bH = new TPolyLine(4,x,y);
  pl_bH->SetFillColorAlpha(8, 0.571);
  pl_bH->Draw("f");

```

And declaration of histogram and canvas:

```
#include "TFile.h"
#include "TTree.h"
#include "TH2D.h"
#include "TH1D.h"
#include "TSystem.h"
#include "TCanvas.h"

#include <string>
#include <vector>
#include <iostream>
#include <iomanip>

using namespace ROOT::VecOps;

//Canvas for lines:
TCanvas *c1 = new TCanvas("c1","Latex",10,53,604,594);   	        

 TH2D *display__1 = new TH2D("display__1","b-hadron display",1000,-100,100,1000,-100,100);

```

All values like truth\_PV are taken from date file. I am sorry that I do not have permit to post whole macro.

---

<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, 2022, 2:58pm UTC](https://root-forum.cern.ch/t/tpolyline-outside-of-2dhistogram/50844/4 "2022-07-20T14:58:56Z")

</div>

Can you post a running macro?

---

<div class="post-metadata">

**Author:** ![Gec](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@Gec](https://root-forum.cern.ch/u/Gec)\
**Post date:** [July 20, 2022, 3:16pm UTC](https://root-forum.cern.ch/t/tpolyline-outside-of-2dhistogram/50844/5 "2022-07-20T15:16:10Z")

</div>

Hi @couet

screenshot with outputs in terminal (not so important) and display:

 ![Screenshot_2022-07-20_17-13-43](https://root-forum.cern.ch/uploads/default/original/3X/a/5/a52512c6a0b30676d404b75b128d9d7df89507dc.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:** [July 20, 2022, 3:25pm UTC](https://root-forum.cern.ch/t/tpolyline-outside-of-2dhistogram/50844/6 "2022-07-20T15:25:50Z")

</div>

That does not help. Send a running example.
