[Tex/LaTex] How to create a figure with latex labels and handling transparency in gnuplot

gnuplotlabelstransparency

I am very fond of latex labels in my gnuplot figures, and the way I generate most of them is via the pslatex terminal.

Here, I would like to take advantage of transparency in a figure (superimposed histograms), while keeping latex labels. My problem is that this is not achievable using pslatex, as postscript does not handle transparency.

Of course, I could use the svg terminal, generate the core of the figure with transparency, then generate only the axes using pslatex, then put everything together by hand in inkscape, and save in .pdf (but this is heavy, to say the least).

Do you know if there is any straightforward way to do this inside gnuplot?

Once again, thank you for you time!

PS: for the record, the pslatex procedure I follow has been exposed here: How to set what appears as a title in a document viewer menu bar?.

Best Answer

If I recall correctly, postscript does not support transparency. That means you have to select a terminal that supports transparency (and TeX). In ConTeXt transparency works fine, in the text labels as well as transparent graphs (more information: ConTeXt wiki - Gnuplot). ConTeXt uses it's own terminal (based on the metapost terminal). You could give the metapost terminal a try.

This example is taken from the Gnuplot home page - demos and slightly modified; maybe there's something similar you can do in LaTeX.

\usemodule [gnuplot]

\definecolor [mytrans] [r=0.7,t=0.5,a=1]
\starttext

\startGNUPLOTscript [plt]
set clip two
set style fill  transparent solid 0.50 noborder
set key title "Gaussian Distribution"
set key inside left top vertical Left reverse enhanced autotitles nobox
set key noinvert samplen 1 spacing 1 width 0 height 0 
set style function filledcurves y1=0
set title "\\color[mytrans]{Transparent} filled curves" 
set xrange [ -5.00000 : 5.00000 ] noreverse nowriteback
set yrange [ 0.00000 : 1.00000 ] noreverse nowriteback
unset colorbox
Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )
d1(x) = Gauss(x, 0.5, 0.5)
d2(x) = Gauss(x,  2.,  1.)
d3(x) = Gauss(x, -1.,  2.)
GPFUN_Gauss = "Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )"
GPFUN_d1 = "d1(x) = Gauss(x, 0.5, 0.5)"
GPFUN_d2 = "d2(x) = Gauss(x,  2.,  1.)"
GPFUN_d3 = "d3(x) = Gauss(x, -1.,  2.)"
plot d1(x) fs solid 1.0 lc rgb "forest-green" title "µ = 0.5 $\\sigma$ = 0.5",    d2(x) lc rgb "gold" title "µ =  2.0 $\\sigma$ = 1.0",    d3(x) lc rgb "red" title "µ = -1.0 $\\sigma$ = 2.0"
\stopGNUPLOTscript

\useGNUPLOTgraphic [plt]

\stoptext

The result:

result

Tested with context 2011.05.18 18:04, gnuplot 4.7 patchlevel 0