Sunday, September 18, 2011

transparency in gnuplot

There is options to set the fill color in gnuplot to be transparent. But some friends of mine ofen complained that it never works. This is because to let the transparency really work, you also need to choose a transparency supported terminal type. For raster graphics "png" may be a choice, and for vector graphics it may be "pdf". You can use command "help transparent" to see the details.
There is an example.
set sample 500
set title "Maxwell speed distribution"
set xlabel "Speed [(2kT_c/m)^{1/2}]"
set ylabel "Probability Intensity f(v)"
set style fill transparent solid 0.5
set key Left
set term png truecolor enhanced font "Times,15"
set output "maxwell_speed_distribution.png"
plot [0:5] f(x,0.1) w filledcurves x1 title "T=0.1T_c",\
           f(x,1)   w filledcurves x1 title "T=T_c",\
           f(x,5)   w filledcurves x1 title "T=5T_c"
set term pdf enhanced
set output "maxwell_speed_distribution.pdf"
Note that when transparency is used in png terminal, the "truecolor" option must be selected.

The png file is shown below and the pdf file can be downloaded here.


  1. What version of gnuplot are you using? I cannot find a version supports both transparent and term png. Thanks!

  2. tiancaicai:
    I use gnuplot4.4. If you want png terminal to support "transparent" you may have to use "Truecolor" option when you set the terminal, i.e.,"set terminal png truecolor"

  3. Your example works fine. Cannot seem to get transparency to work with data rather than functions. Ideas?

    1. I have tried to plot with data file. And it worked well. Maybe I can give some more advices, if you show your code.

    2. Hi....I have tried a lot to plot with gnuplot (4.6 even) a transparency figure following your advise, but unfortunately I could not do that...even for the 4.6 it say me there is not term png or there is a unknown or ambiguous terminal type...please cold you help me!! I have already done every thing and nothing works....

    3. This is a strange problem. I do not exactly know why. Maybe your gnuplot is not properly installed, or there is a lack of some graphical library files in your operating system.
      Type in the command "set term", and see whether the png terminal is listed.

    4. Hi, I tried to use "set style fill solid 0.5" to plot with data file, but it doesn't work. Can you tell me how to do it?

    5. 你是不是选择了一个不支持透明色的terminal?gnuplot4.6个terminal对透明色的支持如下:
      Terminal solid pattern pm3d
      gif no yes no
      jpeg yes no yes
      pdf yes yes yes
      png TrueColor index yes
      post no yes no
      svg yes yes yes
      win yes yes yes
      wxt yes yes yes
      x11 no yes no

  4. Yes, you are right, there are: xterm, vttek, unknown, tpic,tkcanas,tgif,texdraw,tek410x,tek40xx,svg,regis,qms,pstricks,pstex,pslatex,postcript,pcml5,mp,mif,latex,imagen,hpgl,hp2468,hp2623A,gpic,fig,epslatex,emtex,emf,eepic,dxf,dumb,corel,context,cgm,canvas, amazing there is not png option, could you advise me something in order to fix it? Thanks a lot!!

    1. Reinstall your gnuplot. If it still does not work, then check if there is a png graphical library on your computer.


Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.