来自文件的gnuplot xrange

时间:2017-03-01 13:14:49

标签: datetime plot gnuplot

我使用gnuplot用数据文件中的时间戳绘制不同的温度测量值,如下所示:

”id";"timestamp";"1";"2";"3";"4";"5";"6";"7";"8";"9";"10";"11";"12";"13";"14";"15";"16";"17";"18";"19";"20";"21";"22";"23";"24"
"925";"2017-02-22 06:49:29";"68";"69";"56";"76";"88";"95";"96";"104";"94";"177";"85";"80";"84";"92";"109";"58";"45";"49";"55";"13620";"132";"105";"54";"57"
"926";"2017-02-22 06:49:34";"69";"68";"56";"76";"89";"95";"97";"104";"95";"177";"85";"79";"84";"92";"117";"58";"125";"49";"56";"13620";"132";"105";"54";"58"
"927";"2017-02-22 06:49:40";"68";"68";"56";"76";"88";"94";"96";"104";"95";"177";"85";"79";"85";"92";"90";"58";"465";"50";"57";"13620";"132";"105";"54";"58"
"928";"2017-02-22 06:49:46";"68";"68";"57";"76";"88";"94";"96";"105";"94";"178";"84";"79";"185";"93";"104";"58";"46";"50";"57";"13620";"132";"105";"54";"58"
"929";"2017-02-22 06:49:52";"69";"69";"56";"76";"88";"94";"96";"105";"94";"178";"84";"80";"185";"93";"104";"58";"46";"50";"57";"13620";"132";"105";"54";"58"

根据" id"绘制温度。工作正常,但将其连接到时间戳还没有工作。 我将xdate的格式设置为time并指定如下格式:

set xdata time
set timefmt "\"%Y-%m-%d %H:%M:%S\””
#set xrange ['"2017-02-23 05:00"':'"2017-02-23 17:00"']

set tics font",8"
set link x2
set x2tics format "%d.%m.%Y\n%H:%M" time offset 0,-1
set xtics format "" 

如果没有设置xrange,那么情节看起来不错,但是给了我以下内容,

set xrange [ * : * ] noreverse nowriteback  # (currently ["\"1970-01-01 00:15:00??":"\"1970-01-01 03:00:00??"] )

我想从我的文件更改为实际时间戳。 如果我手动设置,

set xrange ['"2017-02-23 05:00"':'"2017-02-23 17:00"']

轴上的时间是正确的,但没有绘图。

使用时间戳直接绘制数据只会得到一个值,也会使用错误的时间轴。

我试图定义x2ticlabels(2),但它没有工作并给了我一个错误

plot    raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($12/10):x2tic(2)
"wrx_temperature1.1.gp", line 68: warning: add_tic_user: list sort error

我试图弄清楚如何让它发挥作用但是现在我只是尝试了一遍又一遍地工作的相同想法。

也许有人遇到同样的问题并找到了解决办法,或者找到了一些不同的方法来解决这个问题?

我使用的gnuplot是5.0版补丁级别5最后修改2016-10-02

我附上了我当前情节的照片。 Here

这里是我使用的代码:

    #raw_temperatures_datafilename = './../../../../measuring_data/wrx01_data_20170221x0X/20170221x00/raw_temperatures.csv'
raw_temperatures_datafilename = 'raw_temperatures.csv'
set datafile separator ";"

## 20170221x01 (...6020): Prozessbereich
# csvminline = 500
# csvmaxline = 3300
csvminline = -1
csvmaxline = -1

linewidth = 0.8

set style line 1 lw linewidth lt rgb "#CC0000"
set style line 2 lw linewidth lt rgb "#003399"
set style line 3 lw linewidth lt rgb "#009900"
set style line 4 lw linewidth lt rgb "#000000"
set style line 5 lw linewidth lt rgb "#0099FF"
set style line 6 lw linewidth lt rgb "#CC9900"

# set key autotitle columnhead
# unset key


### output
## use svg
 set terminal svg size 1920,1200 fname 'Verdana' fsize 8
 set terminal png size 2400,1400 font 'Verdana,8'
 set output raw_temperatures_datafilename.'.png'
## use screen
#set terminal wxt size 1800,900 enhanced font 'Verdana,8' persist

set key right top
set key box opaque
set grid
set lmargin 10
set rmargin 10

set multiplot # layout 3,1

set size 1, 0.7
set origin 0, 0.3
set bmargin 0

set title "Temperaturverlauf\n[Temperatur]=grad Celsius"

## first graph
set xdata time
set timefmt "\"%Y-%m-%d %H:%M:%S\""
# set xrange ['"2017-02-23 05:00"':'"2017-02-23 17:00"']
set tics font",8"
set link x2
set x2tics format "%d.%m.%Y\n%H:%M" time offset 0,-1
set format x ""
set yrange [0:550]
set ytics 0,50,500
set ylabel "Reaktor und Prozess"
plot    raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($12/10) title 'MARTY unten; E17 [10]' with lines ls 1, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($23/10) title 'MARTY oben; E10 [21]' with lines ls 2, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($11/10) title 'Separator; E16 0x09 [9]' with lines ls 3, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($16/10) title 'Separator Zuf¸hrung; E15 0x06 [14]' with lines ls 1, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($17/10) title 'Separator Abgang; 0x0D [15]' with lines ls 5, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($18/10) title 'Br¸cke; E20 0x29 [16]' with lines ls 4, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($3/10) title 'Fackelrohr; E19 0x00 [1]' with lines ls 4

#raw_temperatures_datafilename using ($1):($18/10) title '[16] 0x29 E20 Br¸cke' with lines, \
#raw_temperatures_datafilename using ($1):($3/10) title '[1] 0x00 E19 Fackelrohr' with lines, \
#raw_temperatures_datafilename using ($1):($4/10) title '[2] 0x01' with lines, \
#raw_temperatures_datafilename using ($1):($5/10) title '[3] 0x02' with lines, \
#raw_temperatures_datafilename using ($1):($6/10) title '[4] 0x20' with lines, \
#raw_temperatures_datafilename using ($1):($7/10) title '[5] 0x22' with lines, \
#raw_temperatures_datafilename using ($1):($8/10) title '[6] 0x23' with lines, \
#raw_temperatures_datafilename using ($1):($9/10) title '[7] 0x25' with lines, \
#raw_temperatures_datafilename using ($1):($15/10) title '[13] 0x27' with lines, \
#raw_temperatures_datafilename using ($1):($13/10) title '[11] 0x28' with lines, \
#raw_temperatures_datafilename using ($1):($14/10) title '[12] 0x26' with lines, \
#raw_temperatures_datafilename using ($1):($10/10) title '[8] 0x07 Separator Zuf¸hrung' with lines, \
#raw_temperatures_datafilename using ($1):($21/10) title '[19] 0x0E Eintrag' with lines
#raw_temperatures_datafilename using ($1):($24/10) title '[22] ' with lines

unset x2tics

## second graph
unset title
set size 1.0, 0.15
set origin 0.0, 0.15
set tmargin 0
set yrange [0:240]
set ytics 0,50,220
set ylabel "Prozessgas"
plot    raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($19/10) title 'Prozessgas ein; 0x10 [17]' with lines ls 1, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($20/10) title 'Prozessgas aus; 0x11 [18]' with lines ls 2

## third graph
set bmargin
set size 1.0, 0.15
set origin 0.0, 0.0
set tmargin 0
set xtics format "%H:%M" time
set yrange [0:55]
set ytics (0,10,20,30,40,50)
set ylabel "Kondensation"
plot    raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($25/10) title 'K¸hlwasser ein; 0x16 [23]' with lines ls 1, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($26/10) title 'K¸hlwasser aus; 0x17 [24]' with lines ls 2, \
        raw_temperatures_datafilename every ::csvminline::csvmaxline using ($1):($22/10) title 'Sensor K¸hlwasserbeh‰lter; [20]' with lines ls 3

unset multiplot

1 个答案:

答案 0 :(得分:0)

通常我会使用像

这样的东西
set terminal pngcairo size 960,400
set output "times.png"

set datafile separator ";"
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%Y-%m-%d %H:%M:%S"

# adjust the plot on the picture
set lmargin at screen 0.1
set rmargin at screen 0.9
set xtics 10
# end adjust

plot "raw_temperatures.csv" u 2:3 w l

结果如下:

x date and time

我不确定您的脚本,但是您尝试过类似... using ($2):($19/10) ...而不是... using ($1):($19/10) ...的内容吗?您可能只是尝试将第一列(id列)作为时间戳读取。在这种情况下,gnuplot会将id解释为从1970-01-01 00:00:00开始的秒数。

<强>更新

如果您只是想镜像轴标签,这可能会有所帮助:

set terminal pngcairo size 960,400
set output "timesc.png"

# datafile
set datafile separator ";"
set timefmt "%Y-%m-%d %H:%M:%S"

# x1 axis (bottom)
set xdata time
set format x "%Y-%m-%d\n%H:%M:%S"
set xtics  10    # A tic every 10 seconds.

# x2 axis (top)
set x2data time
set format x2 "%Y-%m-%d\n%H:%M:%S"
set x2tics 10 offset 0,-1  # A tic every 10 seconds. Small adjustment to fit on screen.
# set x2range ...

# plot adjustments
set rmargin at screen 0.93

plot "raw_temperatures.csv" u 2:3 w l lw 2

结果如下:

x labels mirrored

如果要对x2进行绘图,则必须更改绘图命令:

plot "raw_temperatures.csv" u 2:9 w l lw 2 axes x2y1, \
     "raw_temperatures.csv" u 2:8 w l lw 2