# Transparent plot

Okay, that post was a little bit to early, I think I’ve found the solution:
{
TCanvas *c1 = new TCanvas(“c1”,“transparent pad”,200,10,700,500);
c1->SetFillStyle(4000);
c1->SetFrameFillStyle(4000);

TH1F* h = new TH1F(“h”,“h”,100,-5,5);
h->FillRandom(“gaus”);

h->SetFillStyle(4000);
h->Draw();

pad1->Update(); //this will force the generation of the “stats” box
c1->cd();

}

I’ve attached the saved .eps file and also a .ps file that I’ve created in latex using said .eps file. I’ve had to rename the .eps file to .C since I couldn’t upload it otherwise (why??)
test.C (11.7 KB)
test.ps (45.2 KB)

I’ve tried the macro given in the last post, adding the following 3 lines to save the histogram:

c1->SaveAs("./test.pdf");
c1->SaveAs("./test.eps");
c1->SaveAs("./test.png");

but when I include the saved histogram file into a LaTeX document the pad is not transparent.

Attached is a small macro attempting to produce the desired output, and 3 images showing that none of the output files give the desired result (transparent histogram/pad background).

The canvases (i.e. the area surrounding the axes titles and labels) are transparent for .eps and .pdf files.
But the pad (interior area) is still solid white.

For .png files neither the canvas nor the pad is transparent. Both are solid white.
According to http://root.cern.ch/root/html/TAttFill.html

but this is not what I am seeing.

Does anyone know how to make an output file where all background areas are transparent?

Thanks!

(I am using ROOT v5.99/03)

test.C (559 Bytes)

see attached files
transtex.pdf (23.6 KB)
transtex.tex (191 Bytes)
trans.pdf (14.3 KB)
trans.C (477 Bytes)

Unfortunately, I don’t see the transparency in your attached files because your background is white.

I’ve attached a modified .tex file which has a yellow background, and the pad created with your macro is still solid white. The histogram file you attached also appears white in the resulting .pdf file created with pdflatex.
transtex.tex (234 Bytes)
transtex.pdf (23.6 KB)

Yes … sorry

{
TCanvas *c = new TCanvas("c","transparent pad",200,10,700,500);
c->SetFillColor(0);
c->SetFillStyle(0);
p->SetFillColor(0);
p->SetFillStyle(0);
p->SetFrameFillColor(0);
p->SetFrameFillStyle(0);
p->Draw();
p->cd();
TH1F* h = new TH1F("h","h",100,-5,5);
h->FillRandom("gaus");
h->Draw();
c->SaveAs("trans.pdf");
c->SaveAs("trans.eps");
c->SaveAs("trans.png");
}



With that code I’m still getting a white background.
Were you successful in viewing the yellow background behind the histo in transtex.pdf?

with that code I did:

root [0] .x trans.C
Info in <TCanvas::Print>: pdf file trans.pdf has been created
Info in <TCanvas::Print>: eps file trans.eps has been created
Info in <TCanvas::Print>: file trans.png has been created
root [1] .q
$pdflatex transtex.tex and I get the attached file. As you see we can see canvas is transparent. You can see the yellow background of the Latex page. transtex.pdf (23.6 KB) Yes, your result is exactly what I am trying to do. But unfortunately it’s not working on my machine, I get the result in attachment. I’m not sure what the problem is. Do you have any suggestions on what to look for? Thanks! I’m using this version of Root: $ git checkout -b v5-99-06 v5-99-06

with this configuration:

./configure --enable-mathmore --enable-roofit --enable-minuit2 --enable-table --enable-gdml --enable-unuran

on 64-bit Ubuntu 13.04
transtex.pdf (24.1 KB)

The plot you show make me think you forgot to add the Frame related code. Have you tired exactly the macro I sent ?

Yes, the macro is exactly the same. I didn’t change anything.
There were no errors or warnings when I ran it.
Any ideas what the problem could be?

I just ran again le macro with root 6 … I get the exact same plot as before… it works for me…
can you generate the PS (trans.ps) ? and send it to me … (olivier.couet@cern.ch)

Here is .ps file.
trans.ps (10.2 KB)

Yes … very different for my … can you start root with option -n ?

Perfect. With option -n I get the desired output.
Thank you!
transtex.pdf (23.6 KB)

So you have some setup in the rootlogon.C file which creates that problem.
Ok fine.

Thanks couet for the instructions, I managed to get a transparent canvas in the pdf output.

Now, I tried to save the canvas as .tex

c->SaveAs("trans.tex")

and then include it in my latex document “test_transparent.tex”

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{figure}
\input{trans.tex}
\caption{Image ({\tt trans.tex}) generated thanks to {\tt TTeXDump}}
\end{figure}
\end{document}

When compiling with “pdflatex test_transparent.tex”, the resulting background is black (see attached pdf), so I think there is a bug in the .tex export function. If I hack the “trans.tex” file by removing these three lines, the background is correctly transparent:

\definecolor{c}{rgb}{1,1,1};
\draw [pattern=, pattern color=c] (0,0) rectangle (20,13.5632);
\draw [pattern=, pattern color=c] (0,0) rectangle (20,13.5632);

This hack removes also the bounding box (transparent space around the histogram), which is interesting as this extra white space is normally not needed when inserting into a latex document, which manages by himself the separation with normal text and so on.

But maybe, one could add a boolean option to the export function to .tex such that:

• Normal behaviour: draw a bounding rectangle with transparent fill color (correct the “black bug”).
• Remove bounding box behaviour: remove completely the bounding rectangle.

The second option would also be interesting for the SaveAs(".pdf") function. Otherwise, one has to open each pdf figure in inkscape, and save it again as pdf with “export area is drawing” option instead of “save area is page”.
test_transparent.pdf (30.5 KB)

Transparency does not work for Tex output

This issue is now solved in v5-34-26, TTexDump can handle transparent pads. Thanks.

I have a question on this. I found that, one has to invoke the lines on every single object which might span an area in the canvas, be they pads, boxes etc. I tried with gStyle->SetFillColor(0); ... etc (same lines that I use for canvas etc) and it does not work. This is rather cumbersome, is there a way to apply this globally?

Maybe related, but it seems that I must invoke -n for this to work. This confuses me, since I don’t have any rootrc or rootlogon.C files. Why is this so?

Cheers,
Afiq

This as nothing to do with transparency in TLatex. Can you make an other post with an example showing your problem ?