Search code examples
gnuplotheatmap

Gnuplot: How to continue a pm3d plot to the outside of the set range?


I have a problem with plotting my data points with pm3d in gnuplot. In my data file, the points (2-dim domain) are not rectangular aligned, but parabolic as shown in this figure, where the data points are not aligned exactly above each other. My goal is to create a heatmap with pm3d for a specific xrange where the heatmap is continued to the borders of the selected xrange.

What I did:

Plotted the data set with pm3d using the following minimal code example:

set terminal qt
set xrange [-0.25:1.00]
set view map
splot "data.txt" u 1:2:3 with pm3d

What I got:

A heatmap of my data file, but with ugly corners at the border points at where I cut my x-domain, because the border points are not aligned "above" each other.

What I expected:

A heatmap where the "heat" values are continued to the real border of the domain as it is the case for a simple "with lines" plot, shown in this figure.

My attempts so far to achieve what I expected:

I tried several pm3d options, including the option clip1in, which only requires 1 clip of a "heat rectangle" to be inside the domain, but the result was that the corners are no laying outside of the domain, which doesn't solve the problem unfortunately.

Additional information: OS: Ubuntu 20.04

$ gnuplot -V
gnuplot 5.2 patchlevel 8

If anybody knows how I achieve what I'm trying to do, it would be nice to share that knowledge!

Cheers!


Solution

  • Gnuplot 5.4 does offer this sort of smooth clipping on the z coordinate, but unfortunately that doesn't help because you want clipping on x in this case. Here is an example of performing x clipping by manual intervention. The complicated expression for the x coordinate is just to generate points with a non-orthogonal grid.

    xclip(x) = x > 6. ? 6. : x    # clip x to maximum value of 6.
    f(x,y) = sin(sqrt(x*x + y*y)) # some function to plot
    set sample 21; set isosample 21
    set view map
    set xrange [-6 : 6]
    unset key    
    set multiplot layout 1,2
    
    set title "No clipping"
    splot '++' using       ($1+$2*$2/10.) :($2):(f($1,$2)) with pm3d
    
    set title "Manual clipping at x=6"
    splot '++' using (xclip($1+$2*$2/10.)):($2):(f($1,$2)) with pm3d
    unset multiplot
    

    enter image description here