Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Month tics, how to set

Tags:

gnuplot

In GnuPlot:

How to set xtics to 1st of every month?

set xtics would not work for me the as the number of seconds per month varies.

set xmtics
does not work for me because months are displayed without years and it is not shown to which year belongs a month.
like image 231
porton Avatar asked Dec 09 '12 08:12

porton


1 Answers

set xtics will work ok if you set the number of seconds to the average number of seconds in a month.

I worked this out by assuming 365.2425 days in the average year, dividing by 12 to find the average days per month (approximately 30.4), multiplying by hours per day then seconds per hour, i.e:

365.2425 / 12 * 24 * 3600 = 2629746

Assuming your data was formatted as year-month and value, i.e:

2016-01 10000
2016-02 12000
2016-03 10500

Then you’d need commands such as:

set xdata time
set timefmt "%Y-%m"
set format x "%b/%y" # Or some other output format you prefer
set xtics "2016-01", 2629746, "2016-03"
plot "mydata.dat" using 1:2 with linespoints

If you want to set xtics in multiples of months then just add a multiplier in the set xtics line, e.g to get quarterly marks:

set xtics "2016-01", 3*2629746, "2016-12"

I found that if I assumed the number of days in a month to be 30 or 31 then some at some point in the chart, months would be missing their xtics.

like image 80
Warwick Avatar answered Sep 29 '22 12:09

Warwick