Gnuplot, plotting a graph with text on y axis

三世轮回 提交于 2019-12-17 20:28:54

问题


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:



来源:https://stackoverflow.com/questions/22995429/gnuplot-plotting-a-graph-with-text-on-y-axis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!