Why does the 'set table' option in Gnuplot re-write the first entry in the last line?

白昼怎懂夜的黑 提交于 2019-12-02 14:13:41

问题


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

then I get something like

10 1
11 3
12 2 
15 1 

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?


回答1:


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

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 ...".



来源:https://stackoverflow.com/questions/18346952/why-does-the-set-table-option-in-gnuplot-re-write-the-first-entry-in-the-last

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