Jonas Greitemann
Jonas Greitemann

Reputation: 1071

Avoid interpolation of discontinuities for periodic data

I have a complex-valued data file and I want to plot the phase information separate from the absolute values in a flat pm3d plot. I defined a cyclic color palette between -pi and pi like this

set palette model HSV
set palette define (-pi 0 1 1, pi 1 1 1)
set palette maxcolors 1000

i.e. I assign the two 'reds' on the rim of the HSV color wheel to the end points of the phase domain (±pi). I then go about to plot the data like this:

set pm3d map
set cbrange [-pi:pi]
splot 'datafile' w pm3d

The result looks like this: Phase plot with apparent discontinuity at +/- pi

As you can see, there is an artifact in places where the phase value jumps from -pi to pi as the plot algorithm interpolates the two opposite values, yielding a color close to 0 (cyan). Is there a way to avoid this artifact from within gnuplot? Of course, I could always manipulate the data in a way that avoids a discontinuity and assigns phases outside the standard [-pi:pi] domain but I'd rather not.


EDIT: You can reproduce a plot similar to the above one with a function instead of a data file:

I = {0,1}
set xrange [0:3]
set yrange [0:3]
set isosample 100
splot arg(exp(I*x*y)) w pm3d

Upvotes: 4

Views: 1009

Answers (1)

Miguel
Miguel

Reputation: 7627

I insist as in my comments that usually it's a better idea to, whenever possible, do color map plots using with image, especially because with vector-image terminals the (non) compression of pm3d can lead to very large image sizes. However, you have a very specific situation because you want interpolation. I have explored the different options of set pm3d corners2color which determines how the interpolation between neighboring grid sites is done. Some of the options might get your rid of the problem, judge by yourself:

set palette model HSV
set palette define (-pi 0 1 1, pi 1 1 1)
set palette maxcolors 1000
set pm3d map
set cbrange [-pi:pi]
I = {0,1}
set xrange [0:3]
set yrange [0:3]
set isosample 100

unset tics
unset colorbox

set term pngcairo size 640,4096; set output "out.png"
set multiplot layout 9,1

do for [mode in "mean geomean median min max c1 c2 c3 c4"] {

eval "set pm3d corners2color ".mode

set title mode            
splot arg(exp(I*x*y)) w pm3d not

}

enter image description here

Upvotes: 1

Related Questions