1

I have some csv data I'm trying to plot in gnuplot.

example:

1,2014-11-07T17:01
2,2014-11-08T11:53
3,2014-11-08T18:50
4,2014-11-09T09:42
5,2014-11-10T11:40
6,2014-11-11T12:34

I'm using

set xtics format "%a"

to show a short day name of the week (Mon, Tue, Wed) which is shown once per day at midnight.

How can I get gnuplot to show the xtics at midday/noon/12pm rather than at midnight?

John
  • 5,672
  • 7
  • 34
  • 52

1 Answers1

1

This is a bit similar to the question mixing date and time on gnuplot xaxis. It's basically about extracting the timestamp for the first noon based on the first date in your data file. Then you can use this timestamp as start for setting the xtics.

The extraction of the first noon is done with stats, strptime and some other time functions:

reset
fmt = "%Y-%m-%dT%H:%M"
set datafile separator ','
stats 'test.txt' using (strptime(fmt, strcol(2))) every ::::0 nooutput
t = int(STATS_min)
t_start_midnight = t - tm_hour(t)*60*60 - tm_min(t)*60 - tm_sec(t)
t_start_noon = t_start_midnight - 12*60*60

Then you can plot your data with

set xdata time
set timefmt fmt
set xtics t_start_noon, 24*60*60

set format x '%a'
plot 'test.txt' using 2:1 with lp pt 7 ps 2 notitle

Note, that stats doesn't work in time mode, and must be invoked before set xdata time.

xtics at noon

Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187