1
votes

I have to plot a time series in gnuplot. I know that there is a way of formatting the x axis to show the dates, but the file that I want to plot must to have the dates in the column time. For example if I had to plot this time series:

TIME    VAR 1
01/01/79    -1.8351
01/02/79    0.6315
01/03/79    -1.3365
01/04/79    2.1251
01/05/79    -0.6708
01/06/79    -3.3965
01/07/79    -0.2298
01/08/79    0.4807
01/09/79    -2.4213
01/10/79    -0.5998
01/11/79    -1.0238
01/12/79    -0.2025
01/13/79    0.4362
01/14/79    -1.1263
01/15/79    3.3197
01/16/79    0.0337
01/17/79    -0.7374

I would use this command lines: set xdata time set timefmt "%m%d%Y" and it works perfectly. But, how to plot time series with this format:

TIME    VAR 1
1   -1.8351
2   0.6315
3   -1.3365
4   2.1251
5   -0.6708
6   -3.3965
7   -0.2298
8   0.4807
9   -2.4213
10  -0.5998
11  -1.0238
12  -0.2025
13  0.4362
14  -1.1263
15  3.3197
16  0.0337
17  -0.7374
18  1.1504
19  -0.1656
20  -0.4389
21  1.4645
22  1.6538
23  1.6362
24  -2.0363
25  -4.9741

and I want to show in x axis the date from 1979 to 2014 (Obviously my ts is longer). Is it possible?

1
Your desired outcome is not clear. You want to appear 1979 instead of 1 in the x-axis and so forth? This will result in a lot of clutter. Maybe you describe in a little more detail. - vaettchen
Try plot[1969:1995][-5:4] "so.dat" u ($1+1969):2 w lp' as a first step (so.dat` being the file with the data above). - vaettchen
@vaettchen... yes that is exactly what I want. I would like that appear the years instead the time. 1979 ->1; 1980->2.... and so on - Erincon
@Christoph. The first column represents the time - Erincon
So is it done for you then? - vaettchen

1 Answers

2
votes

If you want your x-axis to be interpreted and formatted as time, you could do this:

set xdata time                         
set timefmt "%Y"
set xtics rotate
f(x)=sprintf("%d", x+1978)
plot 'test' u (f($1)):2 w lp

This gives the following plot: enter image description here

Edit: If the numbers in the first column represent months starting from 1/1979 (i.e., 1 = 01/1979, 2 = 02/1979), the function f(x) and the the time format have to be adapted properly:

set xdata time                         
set timefmt "%m-%Y"
set xtics rotate
f(x)=sprintf("%d-%d", int(x-1)%12+1, 1979+floor((x-1)/12))
plot 'test' u (f($1)):2 w lp ls 4 lw 3

The above sequence of commands outputs enter image description here