Search code examples
gnuplotbeziercurvesplinesmoothing

Combining acspline with filledcurve on data


I know how to use filledcurve with using 1:2:3 to fill the area between the curves described by columns 2 and 3.

I also know how to smooth a single curve using acsplines with using 1:2:(0.1) (with 0.1 being the smoothing weight for each point).

But I fail to combine the two, i.e. fill the area between two smoothed curves. All variants I try give me error messages like duplicated or contradicting arguments in datafile options.

This is what I tried:

plot 'datafile' using 1:2:3:(0.1):(0.1) smooth acs with lines
plot 'datafile' using 1:2:(0.1):3:(0.1) smooth acs with lines

Is this combination possible at all? How is the syntax then?


Solution

  • I guess you can't combine smooth acspline and with filledcurves, but I also don't know why this shouldn't be possible. Well, as a workaround, plot your smooth acspline curve into a data table first and then plot it with filledcurves.

    Code:

    ### filled acspline curve
    reset session
    
    $Data <<EOD
    1 2
    2 4
    3 3
    4 1
    EOD
    
    # plot your acspline data into a table
    set table $ACSpline
        plot $Data u 1:2 smooth acspline
    unset table
    
    set style fill transparent solid 0.1 
    
    plot $Data u 1:2 w lp pt 7 lc rgb "black" ti "Original data", \
         $Data u 1:2 smooth acspline lw 2 lc rgb "red" ti "acspline", \
         $ACSpline u 1:2 w filledcurves x1 lc rgb "red" ti "acspline filled"
    ### end of code
    

    Result:

    enter image description here

    Addition:

    There is another way to get data into a table. Check help set print. With this, you can get the data of the two splines into one datablock and can plot the area between them. Maybe someone knows a simpler way to achieve this.

    Code:

    ### filled curve between two acsplines
    reset session
    
    $Data <<EOD
    1 2 4
    2 4 1
    3 3 0
    4 1 3
    EOD
    
    # plot your acspline data into tables
    set table $ACSpline1
        plot $Data u 1:2:(1) smooth acspline
    unset table
    set table $ACSpline2
        plot $Data u 1:3:(1) smooth acspline
    unset table
    set print $BetweenSplines
        do for [i=1:|$ACSpline1|] {
            print sprintf("%s %s %s",word($ACSpline1[i],1),word($ACSpline1[i],2),word($ACSpline2[i],2))
        }
    set print
    
    set style fill transparent solid 0.5 
    
    plot $Data u 1:2 w lp pt 7 lc rgb "black" ti "Original data col 2", \
         $Data u 1:3 w lp pt 7 lc rgb "blue" ti "Original data col 3", \
         $ACSpline1 u 1:2 w l lw 2 lc rgb "red" ti "acspline col 2", \
         $ACSpline2 u 1:2 w l lw 2 lc rgb "green" ti "acspline col 3", \
         $BetweenSplines u 1:2:3 w filledcurves lc rgb "yellow" ti "acspline filled"
    ### end of code
    

    Result:

    enter image description here