Gnuplot, plotting a graph with text on y axis

后端 未结 1 1779
终归单人心
终归单人心 2020-12-11 10:03

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

directory  file_sizes
dir1         200
dir1         150
dir2         200
dir3          40


        
相关标签:
1条回答
  • 2020-12-11 10:40

    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

    0 讨论(0)
提交回复
热议问题