1
votes

I have time series for tide data:

2013-06-01 00:00 1.6980
2013-06-01 00:10 1.6880
2013-06-01 00:20 1.6850
2013-06-01 00:30 1.6900
2013-06-01 00:40 1.7030
2013-06-01 00:50 1.7230
2013-06-01 01:00 1.7510
2013-06-01 01:10 1.7870
2013-06-01 01:20 1.8290
2013-06-01 01:30 1.8790
2013-06-01 01:40 1.9350
2013-06-01 01:50 1.9970
2013-06-01 02:00 2.0650
2013-06-01 02:10 2.1380
2013-06-01 02:20 2.2160
2013-06-01 02:30 2.2990
2013-06-01 02:40 2.3860
2013-06-01 02:50 2.4760
etc ...

Question:
How to put a marker on the line if I know the Day of Year and time (hh mm)
(for example: let say I want to put marker on DoY 165 00 00)

So for I can only plot this time series. Here is my script:

set term png size 600,180 font "Helvetica" 10
set style fill transparent solid 0.5 noborder
set output "time_series.png"
set xdata time
set timefmt "%Y-%m-%d %H:%M"
set xrange ["2013-06-09":"2013-06-20"]
set xtics format "%j"
set style line 2 lc rgb 'red' pt 7 # circle
plot "Tide_Obsv.txt" u 1:3 w lines ls 2 notitle

The result that I want is something like this:
enter image description here

Any helps would be greatly appreciated.

Thanks guys.

2

2 Answers

2
votes

You can use strptime to calculate the timestamp which corresponds to the selected day of the year:

t = strptime('%j %Y', '165 2013')

and then plot a single point where the timestamp of your data equals the calculated timestamp:

set xdata time
set timefmt "%Y-%m-%d %H:%M"
set xrange ["2013-06-01":"2013-06-20"]
set xtics format "%j"
set style line 2 lc rgb 'red' pt 7 # circle

t = strptime('%j %Y', "165 2013")
plot "Tide_Obsv.txt" u 1:3 w lines ls 2 notitle, \
     "Tide_Obsv.txt" u 1:(timecolumn(1) == t ? $3 : 1/0) with points pt 7

Note, that for this to work your data file must contain a corresponding time value at 00:00.

For gnuplot 5.0 the timecolumn function has changed a bit and you would need to use timecolumn(1, '%Y-%m-%d %H:%M').

2
votes

This is tricky because it involves a conditional evaluation of a time expression. The way I figured out below is a bit complicated and there might be an easier solution but I could only come out with the following.

I named your data sample data, and it looks like this:

set xdata time
set timefmt "%Y-%m-%d %H:%M"
set xtics format "%j"
plot "data" u 1:3 w l

enter image description here

Since the data you provided does not have day 165 I will work with day 152, which should be the first data point with time 00:00. I am going to save the data above to a file so that I have the day of the year available for conditional evaluation. I will also save the time so I can distinguish between the different data points for different times of the same day:

set xdata time
set timefmt "%Y-%m-%d %H:%M"
set xtics format "%j %H %M"
set table "data2"
plot "data" u 1:3
unset table

Now I have a file that looks like this:

# Curve 0 of 1, 18 points
# Curve title: ""data" u 1:3"
# x y type
"152 00 00"  1.698  i
"152 00 10"  1.688  i
"152 00 20"  1.685  i
"152 00 30"  1.69  i
"152 00 40"  1.703  i
"152 00 50"  1.723  i
"152 01 00"  1.751  i
"152 01 10"  1.787  i
"152 01 20"  1.829  i
"152 01 30"  1.879  i
"152 01 40"  1.935  i
"152 01 50"  1.997  i
"152 02 00"  2.065  i
"152 02 10"  2.138  i
"152 02 20"  2.216  i
"152 02 30"  2.299  i
"152 02 40"  2.386  i
"152 02 50"  2.476  i

I will use the data above for the final graph, eliminate the " marks using sed, and draw the point corresponding to day 152 by conditional evaluation:

set xdata time
set timefmt "%j %H %M"
set xtics format "%j"
plot "< sed 's/\"//g' data2" u 1:4 w l, \
"" u 1:($1 == 152 && $2 == 0 && $3 == 0 ? $4 : 1/0) w p pt 7 lc 0 ps 2

enter image description here

For day 165 you would require $1 == 165 && $2 == 0 && $3 == 0.