Search code examples
plotgnuplot

Gnuplot: splot with data-file only containing x and b(x)


I want to plot the contour of the following function:

f(x,y)=y³*b(x)

My data-file looks something like this:

  x         b(x)
-1         10.123
-0.995     10.112
-0.99      10.100

I am not sure how to make the right splot command as my datafile does not look like (x y z).

Thats my script so far:

reset
f(x,y)=y³*b(x)
set xrange [-6:6] 
set yrange [-5:5]
set isosamples 50
set table 'test.dat'
splot 'Data.dat' u 1:(b(x)=$2, f(x,y))     -------------------------?
unset table

set contour base
set cntrparam bspline
set cntrparam levels incremental -0.1,0.02,0.1
unset surface
set table 'contour.dat'
splot 'Data.dat' u 1:(b(x)=$2, f(x,y))      -------------------------?
unset table

reset 
set xrange [-6:6]
set yrange [-5:5]
unset key
set palette rgbformulae 33,13,10
plot 'test.dat' with image, 'contour.dat' w l lt -1 lw 1.5

Solution

  • Creating a 3D surface directly from the data in your file will not work because their is no y coordinate data. The program knows how to plot data and it know how to plot functions but you have to choose one or the other.

    To treat the plot as a data plot you will need to expand the file to contain x/y/z data (see 'help matrix'). This is probably easier to do outside of gnuplot.

    Alternatively you can recast your function b(x) in some analytic form, possibly by using gnuplot's "fit" command and your existing data file. Suppose for example that a quadratic fit to your data is sufficient:

    b(x) = C0 + C1*x + C2*x*x + C3*x*x*x
    C0=C1=1; C2=C3=0;
    fit b(x) 'test.dat' using 1:2 via C0,C1,C2,C3
    

    Now you have analytic forms for both the x and y dependence of the surface to be contoured

    f(x,y) = b(x) * y*y*y
    set contour base
    set cntrparam bspline
    set cntrparam levels incremental -0.1,0.02,0.1
    unset surface
    splot f(x,y)