我成功使用Gnuplot构建折线图。
现在我想把日期放在x轴上。这是我的数据:
service1 service2 service3
12/28/2014 0 0 0
11/24/2014 1 2 0
10/06/2014 5 4 1
08/30/2014 10 6 0
03/13/2014 15 8 0
在添加日期格式之前,这是我的情节文件:
set term pos eps font 20
set output 'line.eps'
plot "data.dat" using 2 smooth cumulative t 's1' with lines, \
"data.dat" using 3 smooth cumulative t 's2' with lines, \
"data.dat" using 4 smooth cumulative t 's3' with lines
我在我的情节中添加日期格式,如下所示:
set term pos eps font 20
set output 'line.eps'
set xdata time
set timefmt "%m/%d/%y"
set xrange ["01/01/2009":"12/01/2014"]
plot "data.dat" using 2 smooth cumulative t 's1' with lines, \
"data.dat" using 3 smooth cumulative t 's2' with lines, \
"data.dat" using 4 smooth cumulative t 's3' with lines
,错误是:
"plot.plt", line 10: Need full using spec for x time data
之后我尝试添加更改绘图脚本,如下所示:
plot "data.dat" using 1:2 smooth cumulative t 's1' with lines, \
"data.dat" using 1:3 smooth cumulative t 's2' with lines, \
"data.dat" using 1:4 smooth cumulative t 's3' with lines
并给了我错误:
service1 service2 service3
data.dat:1:"plot.plt", line 10: illegal month
似乎与上一张图有所不同。有人能告诉我,如何解决这个问题?我的期望如下图所示,但在x轴上使用月份格式。
由于
答案 0 :(得分:2)
错误消息告诉您,在文件的第一行data.dat
中,包含service1 service2 service3
,gnuplot遇到非法月份......
你可以
every ::1
另一个问题:使用%Y
指定了四位数年份。以下工作正常:
set xdata time
set timefmt "%m/%d/%Y"
set format x "%m/%Y"
set xrange ["01/01/2009":"12/01/2014"]
plot "data.dat" using 1:2 every ::1 smooth cumulative t 's1' with lines, \
"data.dat" using 1:3 every ::1 smooth cumulative t 's2' with lines, \
"data.dat" using 1:4 every ::1 smooth cumulative t 's3' with lines