Gnuplot, plotting a graph with text on y axis

2019-01-20 01:22发布

问题:

I am trying to plot a list with values that looks like this:

directory  file_sizes
dir1         200
dir1         150
dir2         200
dir3          40

Ideally the y axis would have the text (first column) and the numbers (second column) on the x axis. I think a dots plotting would be best as I have a lot of dirs (20-30) and millions of files.

Any ideas?

回答1:

Here is a rather dirty gnuplot script, which does the filtering of the directory names completely inside of gnuplot. I love dirty gnuplot tricks :)

Unfortunately this works only if the directory names don't contain white spaces. If a more sophisticated filtering is required, you must use an external tool for preprocessing.

Here we go:

The idea is to have a variable list which contains all directory names encountered so far, separated by spaces. For any row a function add_dir checks if the current name is already in the list and add it if not. For this to work properly, you must delimit your directory names stored in list with a token, which doesn't occur in a name itself, I choose |.

For plotting, a function index returns the position of the current directory in the list using the words builtin function (this is why directory names cannot have spaces inside):

list = ''
index(w) = words(substr(list, 0, strstrt(list, w)-1))
add_dir(d) = (strstrt(list, d) == 0 ? list=list.' '.d : '')

set offset 1,1,1,1
plot 'file.txt' using (d='|'.strcol(1).'|', add_dir(d), $2):(index(d)):ytic(1) with points notitle

The result is:



标签: gnuplot