Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent background in gnuplot multiplot

Tags:

python

gnuplot

I'd like to get a transparent background in my gnuplot figure. What I coded till now is:

#! /usr/bin/python

from numpy import *
import Gnuplot as gp
import Gnuplot.funcutils

x = (1,2,3)
y=(2,4,5)
x1 = (3,6,8)
g = gp.Gnuplot()
g("set terminal svg size 200,400")
g("set output 'filename.svg'")
g("unset xtics")
g("unset ytics")
g("set multiplot layout 3,1 title 'Title here'")
g("set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb '#ff0000'      behind")
#First
g("set tmargin 2")
g("set title 'Plot'")
g("unset key")
d = gp.Data(x,y,with_="lines")
g.plot(d)
#Secon
g("set title 'Plot2'")
g("unset key")
d1 = gp.Data(x1,y,with_="lines")
g.plot(d1)
#Third
g("set title 'Plot3'")
g("unset key")
d2 = gp.Data(y,x,with_="lines")
g.plot(d2)
g("unset multiplot")

I got a red screen but just the third plot. (Yeah, I have to change the rgb combo to get transparent background color. But, what's it?)

Thanks in advance, FB

like image 634
FrankBr Avatar asked May 15 '12 18:05

FrankBr


1 Answers

Gnuplot can output transparent backgrounds directly, but not for all formats. For example, this can be done for .png:

set term png transparent truecolor
set output 'plot.png'
plot sin(x)

transparent handles the transparency for the background, and truecolor for transparent objects/plot fillings.

Another way I can get a transparent background out of gnuplot is if I output an .eps and convert it to .png or some transparency-supporting raster format.

Gnuplot example:

set terminal postscript enhanced color
set output 'plot.eps'
plot sin(x)

In bash:

convert plot.eps -rotate 90 plot.png

The resulting .png has a transparent background where the .eps does not. This may have to do with the way imagemagick handles transparency. The same does not happen for me converting .svg to .png; it still has a white background.

You might have some luck using a vector graphics editor such as Inkscape to add transparency.

like image 103
andyras Avatar answered Oct 10 '22 10:10

andyras