为什么设置表'Gnuplot中的选项重写最后一行中的第一个条目? [英] Why does the 'set table' option in Gnuplot re-write the first entry in the last line?

查看:57
本文介绍了为什么设置表'Gnuplot中的选项重写最后一行中的第一个条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从已有的数据中创建直方图,只是为了了解频率和箱等信息,因此我设置了一个表格,以便将其绘制出来而不是将其绘制到一个特定的文件中.例如,如果我的数据是

I am trying to create a histogram from some data I have and just to get an idea of the frequencies and bins etc I set a table so that instead of plotting it it put the information about the histogram into a particular file. So for example if my data was

11
12 
11
11
15
12
10

然后我得到类似

10 1
11 3
12 2 
15 1 

其中第二列给出每个条目的频率.但是我注意到的是,当gnuplot创建此文件时,不是得到高于我的东西,而是得到

where the second column gives the frequencies of each entry. But what I've noticed is that when gnuplot creates this file, instead of getting what I get above I get

10 1
11 3
12 2 
15 1
10 1

即在表的末尾再次重复第一个条目.如果我只想绘制直方图,即此文件,那很好,没问题.但是我需要做的是以对数刻度绘制频率,如果我不纠正这一点,即每次手动加载文件,然后摆脱最后一行,这将在趋势的其余部分上绘制一个奇数点我的数据..我想知道为什么会发生这种情况,是否有办法将其关闭?我使用的代码如下:

i.e. the first entry is repeated again at the end of the table. If I wanted to plot just the histogram i.e. this file, its fine, no problem. But what I need to do is to plot the frequencies in logscale and if I don't correct this, i.e. manually load the file each time and then get rid of the last line, this plots an odd point way off the rest of the trend of my data.. I was wondering why this happens and if theres any way to turn it off? The code I use is the following:

set table 'tableavalanchesizeGSA'
bw = 50.0
bin(x,s)=s*int(x/s)
plot 'avalanche_size_GSA.dat' using (bin($1,bw)+bw/2.0):(1.0/2048000) smooth frequency    with points
unset table
set logscale y
plot 'tableavalanchesizeGSA' with points title ''

有人知道为什么会这样吗?如果有自动将其关闭的方法?

Does anyone know why this is happening? And if there's an automatic way of turning it off?

推荐答案

此行为是 gnuplot bug .为了避免此错误,您可以在写入输出文件之前通过 head 将表输出通过管道传输:

This behaviour is a gnuplot bug. To circumvent this bug, you can pipe your table output through head before writing to the output file:

set output "| head -n -2 > tableavalanchesizeGSA"
set table
bw = 50.0
bin(x,s)=s*int(x/s)
plot 'avalanche_size_GSA.dat' using (bin($1,bw)+bw/2.0):(1.0/2048000) smooth frequency with points
unset table

您必须跳过最后两行,因为gnuplot在末尾写了一个空行.另外,您必须明确使用 set output ,当使用 set table"| head ..." 设置输出时,管道似乎无法正常工作.

You must skip the last two lines, because gnuplot writes an empty line at the end. Also you must use set output explicitely, piping seems not to work when setting the output with set table "| head ...".

这篇关于为什么设置表'Gnuplot中的选项重写最后一行中的第一个条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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