user3520630
user3520630

Reputation: 31

Gnuplot, plotting a graph with text on y axis

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?

Upvotes: 3

Views: 1887

Answers (1)

Christoph
Christoph

Reputation: 48390

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:

enter image description here

Upvotes: 4

Related Questions