Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Gnuplot handle png transparency?

Tags:

gnuplot

I'm using the plot 'my_image.png' binary filetype=png with rgbimage feature of gnuplot to superimpose images on a (scarce) scatterplot.

My png's have a transparent background, so I had been hoping that they could 'respect' the grid and axes, but unfortunately they are plotted on top of it with a white, opaque background.

Is there any ways to address this issue ?

Minimal working example

The file 2091450.png is provided by First Google result for Transparent PNG :

set terminal pdfcairo font "CMU Serif" linewidth 4 rounded \
fontscale 1.0 size 29.7cm, 21cm enhanced dashed
set output 'transparency_test.pdf'

set style line 81 lt rgb "#808080"
set style line 80 lt 0  # dashed
set style line 80 lt rgb "#808080"  # grey
set grid back linestyle 80

set border 3 back linestyle 81
plot '2091450.png' binary filetype=png origin=(0,0) dx=1.0 dy=1.0 with rgbimage
like image 623
Bertrand Caron Avatar asked Oct 21 '25 22:10

Bertrand Caron


1 Answers

Several things:

  • Your links gives me only a jpg image despite the URL name (If it would be transparent, you would get only a completely black image as result with the rgbimage style).

  • To plot images with transparency use the rgbalpha plotting style:

    plot 'transparencytest.png' binary filetype=png with rgbalpha
    

    I used the following file transparencytest.png for testing, which works fine:

    enter image description here

  • Why don't you just put the grid and the border to the front layer?

like image 89
Christoph Avatar answered Oct 24 '25 12:10

Christoph