splot with mixing data and parameter

Viewed 64

I have two curves as data points (i. e. a two sets of two-tuples). I want to splot the surface of their weighted sum, the weight being the third axis (so like a smooth transition from one curve to the other).

Example: If I have the functions sin(x) and x**2 / 100, I can achieve it like this:

set isosamples 100
splot [-10:10] [0:1] y * sin(x) + (1-y) * (x**2 / 100)

In my case, however, I do not have functions but values from a data file and I do not know how to combine this with an automatic running value like the weight y in the example above. I tried, e.g. this, but it did not work:

splot [] [0:1] 'datafile' using 1:(y):(y * $2 + (1-y) * $3)

The error I get is undefined variable: y (which is clear). I just don't know how to combine data from a data file and a running parameter.

2 Answers

The first idea which comes to my mind is to plot the "mixed" data into a table. I hope that there are better approaches.

Code:

### mixing of parameter and data
reset session

# create some test data
set table $Data
    plot '+' u 1:(sin($1)):($1**2/100.) w table
unset table

N = 20.0    # float number to avoid integer division
set table $Mix
    do for [i=0:N] {
        plot $Data u 1:(i/N):(i/N*$2 + (1-i/N)*$3) w table
        plot '+' u ("") every ::0::0 w table   # plot "empty line" to disconnect lines
    }
unset table

set view 48,9
set ztics 0.5
splot $Mix u 1:2:3 w l
### end of code

Result:

enter image description here

If you need only a smooth transition, you can use dgrid3d

set table $Data
   plot '+' u 1:($1**2/100.) w table
   plot '+' u ("") every ::0::0 w table   # plot "empty line" to disconnect lines
   plot '+' u 1:(sin($1)) w table
unset table

set view 48,9
set ticslev 0

set dgrid3d 20,100 splines
splot $Data us 1:-1:2 w l 

The pseudocolumn -1 indexes the data set. enter image description here

If your x data are uniform sampled, you can simplify this to

set table $Data
   plot '+' u ($1**2/100.):(sin($1)) w table
unset table

set dgrid3d 20,100 splines
splot $Data matrix us ($2/10-5):1:3 w l

enter image description here

Related