That is not so straightforward, because, as you said, with gnuplot you can set only a single format without any conditionals.
You can solve this by setting the year info manually with set xtics add
, like it was also done in the very similar question mixing date and time on gnuplot xaxis.
Here is a working script:
set xdata time
set timefmt '%Y-%m-%d %H:%M'
set format x '%m/%d'
set xrange ['2013-01-01 00:00':*]
set xtics '2013-01-01 00:00', 3*30*24*60*60
set xtics add ('2013/01/01' '2013-01-01 00:00', '2014/01/01' '2014-01-01 00:00')
plot 'data.dat' using 1:3 with linespoints
So, you first set the format of your input data. Here I've explicitly chosen a different input format, so that you can distinguish where you need which format.
Then you set the output format for the x-axis, which corresponds to what you want for the intermediate months.
Next I explicitly set a start value for the xrange, so that the range starts with January (because I set a label only every three months, with set xtics ...
).
As a last step you manually overwrite the January labels with your custom format. In this form it may be a bit cumbersome if you have several years or if you want to be flexible. It is not a problem to iterate over a range of years. The labels which are outside of the displayed range are ignored. So you could use:
set for [y=2000:2014] xtics add (sprintf('%d/01/01', y) ''.y.'-01-01 00:00')
(Note, that sprintf
cannot be used for the second string.)
With the following test data file data.dat
:
2013-01-01 00:00 12
2013-02-01 12:00 15
2013-04-01 00:00 1
2013-12-01 00:00 11
2014-01-01 14:00 14
2014-04-01 03:00 20
I get the result (using 4.6.5):
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…