How to mark 90 percent in gnuplot

How to mark 90 percentiles in a gnu plot. sample selection

plot [][] "fle.txt" using 1:2 with lines

      

This is how I plot the graph, I want to mark 90% of the plot this is my dataset

time(seconds)  frequency  cumulativeFrequency
10             2          2
11             6          8
12             8          16
13             10         26
14             7          33
15             5          38
16             5          43
17             4          47
18             2          49

      

+3


source to share


2 answers


I don't see any way to do this in gnuplot by itself, but it's not hard to do it with python

-

# percent90.py
import sys
def to_num(iterable):
    for line in iterable:
        columns = line.split()  # split into columns
        if not columns:  # empty line
            continue
        try:
            yield float(columns[1])  # This is a good number -- Yield it and keep going
        except ValueError:  # Not a number on the line
            pass            # just keep going -- do nothing
        except IndexError:
            print line

with open(sys.argv[1]) as fin:
     data = sorted(to_num(fin))

top_10 = data[int(len(data)*0.9):]  #top 10 percent of the data
print(top_10[0])

      

which you can call:



python percent90.py path/to/datafile

      

This will tell you where to place your sign. As far as labeling goes, I would probably do something like this in gnuplot:

YVAL = `python percent90.py path/to/datafile`
set arrow 1 from graph 0,first YVAL to graph 1,first YVAL ls 1 nohead front

      

+4


source


If you just want to compute the 90% data point, it can be done with commands stats

or plot

and gnuplot's internal variables and then draw a line as mgilson suggested:

#!/usr/bin/env gnuplot

set terminal png
set output 'test.png'

# 'every ::1' skips header
stats 'fle.txt' every ::1 

mark = (STATS_max_y - STATS_min_y)*0.9 + STATS_min_y

set arrow 1 from graph 0,first mark to graph 1,first mark ls 1 nohead front

plot 'fle.txt' every ::1

      



This script produces this output:

enter image description here

+3


source







All Articles