Displaying dates and time in Gnuplot

Introduction

When you need to display some specific data in Gnuplot, it may be hard. However, for dates, it is easy, there is already a functionality.

For example, if you want to display date and hour base on a timestamp you have in your data, you can and that is what I will explain.

What we want?

The log file we want to display contains a abscissa which is a time information stored as a timestamp (number of seconds since the epoch). However, we do not want that this big number appears on the abscissa axis. We want the time to be displayed as “31/12 12h” (day and month then only the hour). Moreover, we want a axis which have tic every half-day (midnight and midday).

Specify the type of data

First of all, we will specify that the x axis will display time information.

set xdata time;

We will now define the format of the input data with the timefmt option. Gnuplot use a standard way to describe date and time (try help timefmt to have more information). For us, it is a timestamp so we will use the "%s" time format.

set timefmt "%s";

We also want to format the output time format (the one that will be displayed on the graphic) with the following: - %d for the day - %m for the month - %H for the hour

set format x "%d/%m %Hh";

Finally, we need to define the interval between to ticks in order to displayed ticks only on midnight and midday. For this, we need to make a small calculus.

The timestamp is expressed in seconds. The interval we are taking to is 12 hours. So we need to express 12 hours in seconds which is 43200.

set xtics 43200;

Conclusion

Do not forget to use help to find what possibilities you have for time format.

links

social