1

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?

6
  • 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. Commented Oct 29, 2015 at 5:26
  • 2
    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). Commented Oct 29, 2015 at 6:57
  • @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 Commented Oct 29, 2015 at 14:47
  • @Christoph. The first column represents the time Commented Oct 29, 2015 at 14:48
  • So is it done for you then? Commented Oct 29, 2015 at 15:26

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

8 Comments

That is exactly that I want. But, the dates should be from 1979 to 2014 month by month, I mean it is a monthly time series. Which would be the command if I only want the years?
To format the date's representation in the x-axis you can use set format x "%d/%m/%y"-command. If you wan only the year, use either set format x "%y" (for the last two digits: 79,80,...) or set format x "%Y" (for the four-digit representation: 1979, 1980)
I have another problem. My ts has 423 steps en when I try to plot, it does not plot the correct dates. My time series is monthly, from 1979 to 2014
Can you be more specific? What do you mean by "not [...] the correct days"? Can you provide sample (output)?
Well I mean, when I plot the ts the x axis shows me time from 1979 to 2432 using the entire data. The time forman of my time series is montly, so I would like a command which interpret the time monthly since 1979 to 2014... is it clear?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.