【发布时间】:2018-09-14 19:02:53
【问题描述】:
阅读 gnuplot 手册并没有帮助我解决这个问题,我的互联网搜索也没有取得成果。我正在使用gnuplot 5.2 patchlevel 0
我正在使用文件中的数据绘制下图,并添加了计算得出的移动平均值(代码如下)
使用的文件是这个,graph.dat:
20180607-1200 20.4
20180611-1200 23.2
20180617-1200 22.1
我想在图表底部添加一个直方图,基于另一个具有相同 x 值的文件 histogram.dat:
20180607-1200 18.95
20180611-1200 18.52
20180617-1200 18.76
我已经尝试使用以下代码:
set terminal png size 640,396
set border front lw 1
# Make left y-axis ticks and numbers disappear
set ytics scale 0
set ytics textcolor rgb "white"
set y2tics
set y2range [18.5:25.7]
set output 'graph.png'
set xdata time
set timefmt "%Y%m%d-%H%M"
set xtics timedate
set xtics format "%Y-%m-%d"
set xtics rotate
set mxtics 7
# A week is 604800 seconds
set xtics "20180607-1200",604800,"20180617-1200"
set offsets graph 0.015, graph 0.015, 0, 0
# For moving average
samples(x) = $0 > 4 ? 5 : ($0+1)
avg5(x) = (shift5(x), (back1+back2+back3+back4+back5)/samples($0))
shift5(x) = (back5=back4, back4=back3, back3=back2, back2=back1, back1=x)
# Initialize the running sum
init(x) = (back1 = back2 = back3 = back4 = back5 = sum = 0)
# Plot data, running average, and histogram
plot sum = init(0), \
"graph.dat" using 1:2 axes x1y2 title "graph" with linespoints, \
'' using 1:(avg5($2)) axes x1y2 title "moving average" with linespoints, \
"histogram.dat" using 1:2 axes x1y2 title "histogram" with histogram clustered
但在添加最后一行(以"histogram.dat" 开头)后,它会返回以下错误消息:
plot sum = init(0), "graph.dat" using 1:2 axes x1y2 title "graph" with linespoints, '' using 1:(avg5($2)) axes x1y2 title "moving average" with linespoints, "histogram.dat" using 1:2 axes x1y2 title "histogram" with histogram clustered
^
"grapher.gp", line 35: Too many columns in using specification
我不明白。
我的目标是在底部有一个小直方图,就像在这个构造的例子中一样:
问题:我做错了什么?我如何根据一张图中显示的两个不同文件执行linespoints 和histogram? [我后来发现为此必须使用boxes 而不是histogram - 请参阅下面我自己的答案]
额外问题:有没有比我将它们变成白色更好的方法来避免显示 y1 轴数?
【问题讨论】: