Search code examples
gnuplot

Semitransparent plot with image


I'm trying to plot two matrixes combined, and one of the matrix should be semitransparent. I need that because the experimental data has missing values, and I'd prefer to keep interpolated data distinct from measured. The grid points are same. Gnuplot version is 5.2, patchlevel 8.

Experimental data looks like

8.8128  6.7424  nan
8.8128  6.9776  nan
8.8128  7.2128  nan
..
8.8128  10.976  122.2
..
8.8128  15.2096 nan
8.8128  15.4448 nan

And interpolated (no missing values):

8.8128  6.7424  126.1199426176991
8.8128  6.9776  126.1199426176991
8.8128  7.2128  126.1199426176991
..
8.8128  10.7408 122.21158160029502
8.8128  10.976 122.21158160029502
8.8128  11.2112122.21158160029502
..
8.8128  15.2096 129.1679877531613
8.8128  15.4448 129.1679877531613

If one splots the experimental data with pm3d, many points are missing. plot with image yields Experimental w/ image

The interpolated data, the same command: Interpolated data

The interpolated data is fine to be splotted with pm3d + set style fill transparent solid 0.5 noborder, but then the dimensions of images are very off in multiplot mode.

Both files could be (pre,post)processed basically in any possible way, since datasets are generated using Python.

Is it possible to combine these two datasets, opaque and transparent? Thank you.

Found:

Compose a plot with an image and a plot of a datafile matrix with transparency - this question is about plotting .png.
Assigning transparency to certain elements of a matrix in pm3d map - this is the closest, but no colorbox, also xscale and yscale are lost.


Solution

  • You can try with boxxyerror.

    I use the following python script for generating some data:

    import random
    import math
    
    N = 100
    
    with open("i.dat", 'w') as interpolationfile, open("m.dat", 'w') as measurementfile:
        for x in range(N):
            interpolationfile.write('\n')
            for y in range(N):
                value = 0.5 + 0.5*math.sin(2*math.pi*x*y/(N*N))
                datastring = f"{x+0.5} {y+0.5} {value}\n"
                interpolationfile.write(datastring)
                if random.randint(0, 100) > 90:
                    measurementfile.write(datastring)
    

    The gnuplot script:

    reset
    
    set terminal pngcairo  # directly plot to file, my qt-terminal shows strange artifacts
    set output "output.png"
    
    set nokey
    set cbrange [0:1]
    
    plot "i.dat" u 1:2:(0.5):(0.5):3 with boxxyerror fillcolor palette fillstyle transparent solid 0.2 noborder ,\
         "m.dat" u 1:2:(0.5):(0.5):3 with boxxyerror fillcolor palette fillstyle solid
    

    The parameters in using 1:2:(0.5):(0.5):3 are using <x-column>:<y-column>:<box-width x>:<box-width y>:<color in palette>. My example data has integer x and y coordinates, so my box widhts and heights are 1 (or 0.5 in each direction). The (0.5) in brackets uses these fixed box sizes.

    Please see help boxxyerror for details, there is also the possibility to define absolute corner coordinates for the boxes in separate columns of the input file.

    Without the noborder for the interpolated data there would be nontransparent borders around the boxes.

    This is the result:

    result