使用gnuplot绘制具有缩写值的数据文件 [英] Plotting datafile with abbreviated values with gnuplot

查看:96
本文介绍了使用gnuplot绘制具有缩写值的数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gnuplot数据文件,如下所示:

I have a gnuplot datafile that looks like this:

 1  4810   582   573   587 
 2    99k   67k   56k   40k
 3   119k   82k   68k   49k
 4   119k   81k   68k   49k
 5   120k   81k   65k   45k
 6   121k   82k   65k   44k
 7   124k  106k   97k   86k
 8   128k  134k  131k  131k
 9   128k  130k  131k  135k
10   129k  133k  130k  132k

第一列将在X轴上标记为时间",其余的是相对于时间的不同中断值(即IRQ1,IRQ2,IRQ3,IRQ4)

First column will be on the X-axis labeled as "Time", the rest are the different interrupt values with respect to time (i.e. IRQ1, IRQ2, IRQ3, IRQ4)

以此生成图时的问题是,gnuplot似乎没有将带有K后缀的缩写值解释为千位中的数字,而是将其解释为原始值,例如99、67、119等.将在时间1从大约5000跳到图表中的100.

The problem when generating a plot with this is that gnuplot does not seem to interpret the abbreviated values with the K suffix as numbers in the thousands, but instead as raw values such as 99, 67, 119, etc. Thus the lines will jump from around 5000 at time 1 and drop to around 100 in the graph.

是否有任何选项可以告诉gnuplot自动解释缩写值并相应地绘制它们?

Are there any options to tell gnuplot to automatically interpret abbreviated values and plot them accordingly?

推荐答案

在这种情况下,我认为没有直接的方法可以告诉gnuplot如何解释输入.

I think there is no direct way of telling gnuplot of how to interpret the input in this case.

但是,您可以编写自己的函数,将字符串输入转换为数字

You can, however, write your own function that converts the string-input to numbers

check(x)=(pos=strstrt(x,"k"),\
    pos > 0 ? real(substr(x,1,pos-1))*1000  : real(x))

函数check首先确定字母'k'在输入中的位置. (如果输入x不包含字母'k',则函数strstrt返回'0'.)
如果输入中包含字母"k",请输入,丢弃最后一个字母,将剩余部分转换为数字,然后乘以1000. 如果输入不包含"k",则返回输入

The function check first determines the position of the letter 'k' in the input. (The function strstrt returns '0' if the input x does not contain the letter 'k'.)
If the input contains the letter 'k', take the input, discard the last letter, convert the remaining part to a number and multiply it by 1000. If the input does not contain 'k', return the input

现在您可以绘制数据文件(假设其名称为test):

Now you can plot the data file (assuming its name is test):

plot 'test' u 1:(check(stringcolumn(2))) w l

这应该可以完成!

这篇关于使用gnuplot绘制具有缩写值的数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆