问题描述
我正在尝试绘制一个具有如下所示值的列表:
I am trying to plot a list with values that looks like this:
directory file_sizes
dir1 200
dir1 150
dir2 200
dir3 40
理想地,y轴在x轴上具有文本(第一列)和数字(第二列).我认为最好绘制点,因为我有很多目录(20-30)和数百万个文件.
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.
有什么想法吗?
推荐答案
这是一个非常脏的gnuplot脚本,该脚本完全在gnuplot内部过滤目录名称.我喜欢肮脏的gnuplot技巧:)
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.
我们在这里:
这个想法是让一个变量list
包含到目前为止遇到的所有目录名称,用空格分隔.对于任何行,函数add_dir
都会检查当前名称是否已经在列表中,如果没有,则添加它.为了使其正常工作,必须使用标记来分隔存储在list
中的目录名称,该名称本身不会出现,我选择|
.
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 |
.
对于绘图,函数index
使用内置函数words
返回当前目录在list
中的位置(这就是目录名称内部不能有空格的原因):
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
结果是:
这篇关于Gnuplot,在y轴上绘制带有文本的图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!