Search code examples
gnuplot

Plot specified points first then data from file using gnuplot


I am trying to plot data from two sources: (1) specific points that define a diagonal from (0, 0) to (1, 1), and (2) file containing my analyzed data. Currently, I can do this using the following command:

plot [0:1][0:1] 'sample.dat' using 1:2 with lines,\
'-' title 'random AUC=0.50' with lines dashtype 2
0 0
0 0
0.5 0.5
1 1
e

which outputs the following:

sample AUC plot

However, I want the diagonal line to appear first. How can I achieve this?


Solution

  • If you want to plot the diagonal, simply plot the function x.

    Code:

    ### plot order
    reset session
    
    set size square
    set xrange[0:1]
    set yrange[0:1]
    
    # create some test data
    set table $Data
        plot '+' u 1:(int($1*10+1.5)/10.) w table
    unset table
    
    set key top left
    
    plot x with lines dt 2 title 'random AUC=0.50', \
        $Data u 1:2 w l ti 'sample AUC=0.596'
    ### end of code
    

    Addition:

    If you want to plot arbitrary points instead of x:

    $myPoints <<EOD
    0    0
    0.1  0.2
    0.5  0.7
    1.0  1.0
    EOD
    
    plot $myPoints u 1:2 w lines
    

    Result:

    enter image description here