Reputation: 2037
So I'm using gnuplot to plot some data over time, and I want the bottom axis to be time in hours. There should only be 4-5 hour marks on the x axis, but because the data is so spread out gnuplot seems to want to duplicate each point (probably wanting some minutes data to fill the gaps).
So it looks like this on the x axis:
hours: 0 0 1 1 2 2 3 3 4 4
But should look like this:
hours: 0 1 2 3 4
Is there a setting I can flip to tell it to not duplicate the x axis values?
Here is the .plt file's contents (shortened):
clear
print ""
set terminal pngcairo transparent enhanced font "arial,25" - - - fontscale 1.0 size 1920, 1080
set key outside bottom center box title "spiders in my house over time" enhanced
set key maxrows 4
set key font ",25" spacing 1 samplen 2.9 width 2 height 1
set xlabel "Time (hours)" offset -35 font ",30"
set ylabel "% Average number of spiders (100 means house is filled)" font ",30"
set output "spiders.png"
set title "Average spiders in my house" font ",35"
set datafile separator ","
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set xtics format "%H" font ",25"
set ytics font ",25"
set style line 1 lt 1 lc rgb "red" lw 4
show style line
starting_time = 8631
plot "spider_data.csv" using (timecolumn(1)-starting_time):2 every ::3 ls 1 t "SPIDERS AHHH" with lines
Now if I change set xtics format "%H" font ",25"
to `set xtics format "%H:%M" font ",25"' then it stops duplicating, but that doesn't really fix the problem of wanting only hour ticks.
The .csv file has time, val
format.
Upvotes: 0
Views: 1489
Reputation: 11
you can specifically set the position of the xtics like this:
set xtics 10.,1.,20.
this will put tics in the interval of 18 to 20 with a distance of 1 between them. i.e. 10,11,12,13,...,18,19,20
Upvotes: -1
Reputation: 48390
You must set the xtics
properly. In the default settings, when the total timespan is less than e.g. four hours, the tics resolution is less than one hour, but cannot be displayed because of your settings set xtics format "%H"
.
The xtics
increment is set in seconds, you in order to have tics only at full hours, use set xtics 60*60
.
This is shown in the following example:
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
set xtics format "%H"
set multiplot layout 2,1
plot 'data.txt' using 1:3 with lines
set xtics 60*60
replot
unset multiplot
With data.txt
being:
2013-08-25 18:45:11 100
2013-08-25 19:11:23 200
2013-08-25 20:00:32 400
2013-08-25 21:00:32 300
the result is:
Would have been nice, if you had provided such a minimal data file and the wrong result image.
Upvotes: 2
Reputation: 2037
I ended up "solving" this by just adding minute info. Not quite what I wanted, but it'll do.
set xtics format "%H:%M"
Upvotes: 0