# Background Image in scatter plot

**URL:** <https://root-forum.cern.ch/t/background-image-in-scatter-plot/52036>\
**Category:** Newbie\
**Created:** [October 20, 2022, 12:02am UTC](https://root-forum.cern.ch/t/background-image-in-scatter-plot/52036 "2022-10-20T00:02:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [October 20, 2022, 12:02am UTC](https://root-forum.cern.ch/t/background-image-in-scatter-plot/52036/1 "2022-10-20T00:02:45Z")

</div>

I am trying to add background to my scatterplot, but the background should be limited to just the pad, I tried working based on below documentation,  
[https://root.cern/doc/master/img2pad\_8C.html](https://root.cern/doc/master/img2pad_8C.html)

But my original image get cropped. I didn’t quiet figure out about the x, y coordinate used in pad.

```auto
    TImage *img = TImage::Open("file1545.jpg");
    img->SetConstRatio(kFALSE);
    float d =0.40;
    TCanvas* maincanvas = new TCanvas("maincanvas","img",1080,1920);
    // TPad *p1 = new TPad("i1","i2",0.05,0.55,0.05+d*img->GetWidth()/img->GetHeight(),0,95);
    // TPad *p2= new TPad("i1","i2",0.05,0.55,0.05+d*img->GetWidth()/img->GetHeight(),0,95);
    TPad *p1 = new TPad("i1","i2",0.05,0.55,0.9,0.9);
    TPad *p2= new TPad("i1","i2",0.05,0.55,1.0,1.0);
    p2->SetFillStyle(4000);
    p2->SetFillColor(0);
    p2->SetFrameFillStyle(0);
    p2->SetFrameFillColor(0);
    p1->Draw();
    p1->cd();
    img->Draw();
    maincanvas->cd();
    p2->Draw();
    p2->cd();

```

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [October 20, 2022, 12:57am UTC](https://root-forum.cern.ch/t/background-image-in-scatter-plot/52036/2 "2022-10-20T00:57:26Z")

</div>

[https://root.cern/doc/master/classTPad.html#a76f817b43002e1e9e07a317ed84ac933](https://root.cern/doc/master/classTPad.html#a76f817b43002e1e9e07a317ed84ac933)

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [October 20, 2022, 1:45am UTC](https://root-forum.cern.ch/t/background-image-in-scatter-plot/52036/3 "2022-10-20T01:45:44Z")

</div>

Thank You for help.  
But, even with changing the x-coordinate and y-coordinate it still change shape of image.

---

<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:** [October 25, 2022, 1:35pm UTC](https://root-forum.cern.ch/t/background-image-in-scatter-plot/52036/4 "2022-10-25T13:35:51Z")

</div>

Can you post `file1545.jpg` so we can try your macro ?

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [October 25, 2022, 5:46pm UTC](https://root-forum.cern.ch/t/background-image-in-scatter-plot/52036/5 "2022-10-25T17:46:29Z")

</div>

Thank You for the response,  
The problem comes from different definitions of pixel coordinates. In Computer Vision, conventionally, y-coordinate starts from the top left since they deal with points/pixels on a monitor, whereas, we use the standard convention that the y-axis starts from the bottom left and increases to the top left.  
The issue was solved by the following modification,

```auto
 hist->Fill(x_coordinate,1080-y_coordinate,radius);

```
