Search code examples
gnuplot

Gnuplot: Plot stepwise discontinuities in a cumulative distriubtion


When I plot a cumulative distribution with gnuplot, it interpolates between datapoints; this is seen in the purple curve. How can I plot my data as a stepwise function like the black curve? Something similar to the step method in matplotlib.

enter image description here

Source data

1,1,0
1,2,0
1,3,0
1,4,2
1,5,1
1,6,3
1,7,3
1,8,1
1,9,3
1,10,8
1,11,1
1,12,0
1,13,3

Gnuplot source

set terminal pngcairo font ",14"
set output "cumulative.png"
#set terminal qt font ",14"
set title "Cumulative count" font ",16"
set xlabel "episode"
set ylabel "cumulative count"
set xtics 1
set key bottom right
set grid
unset border

set datafile separator comma
plot "season-01-count.csv" u 2:($3) smooth cumulative title "cumulative count"

Solution

  • Have you done a search or checked the manual at all? Check help steps or check here: http://gnuplot.sourceforge.net/demo_5.2/steps.html or the graph here: How to plot same value until it change?

    Code:

    ### plot with steps
    reset session
    
    $Data <<EOD
    1,1,0
    1,2,0
    1,3,0
    1,4,2
    1,5,1
    1,6,3
    1,7,3
    1,8,1
    1,9,3
    1,10,8
    1,11,1
    1,12,0
    1,13,3
    EOD
    
    set title "Cumulative count" font ",16"
    set xlabel "episode"
    set ylabel "cumulative count"
    set xtics 1
    set key bottom right
    set grid
    unset border
    
    set datafile separator comma
    plot $Data u 2:($3) smooth cumulative with steps lw 2 lc "red" ti "cumulative count"
    ### end of code
    

    Result:

    enter image description here