# Reposition Color Legend TH2 Lego Draw

**URL:** <https://root-forum.cern.ch/t/reposition-color-legend-th2-lego-draw/50710>\
**Category:** Newbie\
**Created:** [July 7, 2022, 4:27pm UTC](https://root-forum.cern.ch/t/reposition-color-legend-th2-lego-draw/50710 "2022-07-07T16:27:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alkegit21](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@Alkegit21](https://root-forum.cern.ch/u/Alkegit21)\
**Post date:** [July 7, 2022, 4:27pm UTC](https://root-forum.cern.ch/t/reposition-color-legend-th2-lego-draw/50710/1 "2022-07-07T16:27:43Z")

</div>

Hi,

How to move the color legend in TH2 lego like this:

 ![c](https://root-forum.cern.ch/uploads/default/original/3X/9/6/9601935f8ad4cf202bd24414a6fe1fc27b2e1ff6.png)  
to this:  
 ![ccor](https://root-forum.cern.ch/uploads/default/original/3X/b/6/b64256e5b5aaa30307208002899e6e3b8ee3cf4c.png)  
inside the code?

Notice that “6” was overlapped with the color legend in the first figure. I know we can move it manually in canvas, but how to do it in code?

Also, “0” and “5” touch each other. How to give some space?

Thanks

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [July 7, 2022, 4:55pm UTC](https://root-forum.cern.ch/t/reposition-color-legend-th2-lego-draw/50710/2 "2022-07-07T16:55:55Z")

</div>

Hi,

> [@Alkegit21](#):
>
> I know we can move it manually in canvas, but how to do it in code?

You can do it with

```c++
palette->SetX1NDC(palette->GetX1NDC()+0.05);
palette->SetX2NDC(palette->GetX2NDC()+0.05);

```

, here is the full example:

```c++
        TCanvas* c1 = new TCanvas("c1", "My awesome plot", 0, 0, 800, 600);
        c1->SetRightMargin(0.18); // to be able to see the z axis title
        TH2F *myHist = new TH2F("myHist", "My histogram;#Delta#phi;#Delta#eta;C(#Delta#eta, #Delta#phi)", 24, -6., +6., 20, -5., +5.);
        myHist->Fill(3., 3., 2500.);
        myHist->Fill(-3., -3., 10.);

        myHist->Draw("LEGO2 COLZ");

        gPad->Update(); // to be able to retrieve the palette pointer

        TPaletteAxis *palette = static_cast<TPaletteAxis*>(myHist->GetListOfFunctions()->FindObject("palette"));
        if (palette)
        {
                palette->SetX1NDC(palette->GetX1NDC()+0.05); // shift x1 by 0.05 to the right
                palette->SetX2NDC(palette->GetX2NDC()+0.05); // shift x2 by 0.05 to the right
        }

        gPad->Update(); gPad->Modified();

```
