# Set transparent background of TCanvas in pyROOT

**URL:** <https://root-forum.cern.ch/t/set-transparent-background-of-tcanvas-in-pyroot/31547>\
**Category:** Newbie\
**Tags:** python\
**Created:** [November 12, 2018, 7:13am UTC](https://root-forum.cern.ch/t/set-transparent-background-of-tcanvas-in-pyroot/31547 "2018-11-12T07:13:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![juifa-tsai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juifa-tsai/32/17428_2.png) [@juifa-tsai](https://root-forum.cern.ch/u/juifa-tsai)\
**Post date:** [November 12, 2018, 7:13am UTC](https://root-forum.cern.ch/t/set-transparent-background-of-tcanvas-in-pyroot/31547/1 "2018-11-12T07:13:21Z")

</div>

Hi,

I am trying to generate a .png file with the transparent background histogram or any plot with pyROOT, but it doesn’t work for me as following setting:

```python
import ROOT
c1 = ROOT.TCanvas("c1", "", 500, 500)
c1.SetFillStyle(4000) 
c1.SetFrameFillStyle(4000) 

h1 = ROOT.TH1F("h1", "", 10, 0, 1)
h1.Draw()

c1.Print("test.png")

```

Even I tried following setting, I get a white background .png instead of transparent.

```python
c1.SetFillColorAlpha(1, 0.) # Use black to check if it goes transparent.

```

- My environments :  
Python : 3.6  
ROOT : v6-14-02

Is it possible to have transparent background with pyROOT, or did I miss something?

Many thanks

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [November 12, 2018, 9:04am UTC](https://root-forum.cern.ch/t/set-transparent-background-of-tcanvas-in-pyroot/31547/2 "2018-11-12T09:04:01Z")

</div>

Hi @juifa-tsai

I can’t reproduce, with the code that you shared I get a canvas with a black background.

```python
import ROOT
c1 = ROOT.TCanvas("c1", "", 500, 500)
c1.SetFillStyle(4000)
c1.SetFrameFillStyle(4000)

h1 = ROOT.TH1F("h1", "", 10, 0, 1)
rndmGenerator = ROOT.TRandom3()
for i in xrange(1000):
    rndm = rndmGenerator.Gaus()
    h1.Fill(rndm)
h1.Draw()

c1.SetFillColorAlpha(1, 0.)

c1.Print("test.png")

```

![test](https://root-forum.cern.ch/uploads/default/original/3X/7/7/77572eccbd02d7c4e30fd1a2a6b02ab53928f0a4.png)

If you run the code above, your png image has white background?

Asking for the opinion of our graphics expert, @couet

---

<div class="post-metadata">

**Author:** ![juifa-tsai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juifa-tsai/32/17428_2.png) [@juifa-tsai](https://root-forum.cern.ch/u/juifa-tsai)\
**Post date:** [November 13, 2018, 2:04am UTC](https://root-forum.cern.ch/t/set-transparent-background-of-tcanvas-in-pyroot/31547/3 "2018-11-13T02:04:22Z")

</div>

Hi @etejedor and @couet

Yes, I have tried your code, I got the white background as the attached file… Is the ROOT version issue or something about my environment?

![test](https://root-forum.cern.ch/uploads/default/original/3X/d/b/db5ab8d6907a880afed2b2ed9f88de47cd911e7c.png)

Many thanks

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [November 13, 2018, 1:11pm UTC](https://root-forum.cern.ch/t/set-transparent-background-of-tcanvas-in-pyroot/31547/4 "2018-11-13T13:11:46Z")

</div>

Hi @juifa-tsai

@couet will be back on Monday. Would it be an option for you to try with a newer ROOT version, in the meantime? What platform are you working on? Is it MacOS?

Enric
