2017-08-21 45 views
0

跟蹤我的電話上的電池的放電/充電。數據形狀像'V'。電量百分比和經過時間(秒),像這樣:GNUPLOT條件「使用」使破碎x軸

100,0 
74,8103 
51,15304 
24,23407 
2,30609 
23,33286 
55,37360 
76,40064 
100,44132 

這裏是我如何處理ñ文件,並將它們一起策劃:

plots="" 
my_xrange=0 

files=system("ls -1B data/*.csv | sort -k2 -t '-'") 
do for [ file in files ] { 
    this="'".file."' ".'using ($2/3600):1 notitle, ' 
    plots=plots.this 
} 
eval('plot '.plots) 

(快樂的情節省略的,因爲太多的鏈接)

然後老闆來,問他的「上坡」分心,我可以積只是「下坡」好看嗎?不用擔心,stats會給我極小,所以我xrange。活泉!

plots="" 
my_xrange=0 

files=system("ls -1B *.csv | sort -k2 -t '-'") 
do for [ file in files ] { 
    stats file using ($2/3600):1 prefix "STATS" nooutput 
    if (STATS_pos_min_y > my_xrange) { my_xrange = STATS_pos_min_y } 
    this="'".file."' ".'using ($2/3600):1 notitle, ' 
    plots=plots.this 
} 
print sprintf('stats: plot xrange is %.2f', my_xrange) 
set xrange [0:my_xrange] 
eval('plot '.plots) 

xrange obliterates some uphills

知道有一定是一種方法,只是沒有繪製上坡,所以我風與using條件。

this="'".file."' ".'using (($2/3600) <= STATS_pos_min_y ? $1 : 1/0) notitle, ' 

有效殺滅上坡,但做了兩個壞事的情節:

  1. X軸值不以前的情節
  2. 情節線被合併匹配對一個另一個

broken things

頂部

我需要使用$ 2/3600,因爲我想用小時來表達事物。哦,當然,我可以寫一個腳本來在數據到達gnuplot之前對數據進行按摩,但這是承認失敗。

什麼我沒有把我的使用using理解?

謝謝。長時間的讀者,首次海報...

+0

我不明白你提到的「兩件壞事」是什麼......你可以發佈你用於yoru「破碎的東西」圖片的兩個數據文件,並解釋你想要取而代之的是什麼? – user8153

+0

對不起!我昨晚做了這個,然後內核恐慌。 我按原樣繪製數據(藍線),並通過僅顯示數據(紫線)的「下坡」部分的條件。我期望紫色正好覆蓋數據下坡部分的藍色。發生的事情是有條件的價值似乎減半了,這對我來說毫無意義。 輸出:http://imgur.com/a/se4yy 數據:在原來的職位 –

+0

設置終端SVG大小如上所示512384 \ \t FNAME「吉爾三世」 FSIZE 9圓角虛線線寬1背景RGB「白色」 集數據文件分離器 「」 設置鍵字體」,6" 文件= 「frustration.csv」 組輸出 'foobar.svg' \t統計文件中使用($ 2/3600):1前綴 「STATS」 nooutput \t陰謀\ \t \t文件使用($ 2/3600):1與linespoints,\ \t \t文件使用($ 2/3600):1:(sprintf(「(%d,%d)」,($ 2/3600),$ 1))標籤中心偏移3.4,.5,\ \t \t \t文件使用((($ 2/3600)<= STATS_pos_min_y)? $ 1:1/0)with linespoints –

回答

1

爲您的整個數據繪圖命令(紫色線)

plot file using ($2/3600):1 with linespoints 

同時,對於有條件的數據(藍線)是

plot file using ((($2/3600) <= STATS_pos_min_y) ? $1 : 1/0) with linespoints 

using語句選擇僅適用於($2/3600) <= STATS_pos_min_y這些數據點。但是,您並未指定x軸上哪些數據點應繪製在哪裏,因此gnuplot假定它只是數據文件中的行號(0,1,2,3,4)。您必須像在無條件圖中一樣指定x軸上的位置:

plot file using ($2/3600):((($2/3600) <= STATS_pos_min_y) ? $1 : 1/0) with linespoints 

應該這樣做。

順便說一句,格式是SO意見相當有限。要發佈代碼,通常更好的方法是在有更多格式選項的地方編輯問題。