2
votes

Gnuplot tends to clutter the x-axis in timeseries plots. See the following image for an example of labels with narrow spacing:

Overlaps in x-axis

Is there a way to make gnuplot avoid such narrow spacing? Preferably this should be done within the gnuplot script to generate the plot.

I generated the plot with the following gnuplot script and a file of random data:

set terminal png
set output "plot.png"

set timefmt "%s"
set xdata time

set xlabel "time"
set ylabel "Random Data"

set boxwidth 600
set style fill solid 0.5

set key below

plot "random.dat" using 1:2 w boxes title ".60"

Note: I am using Gnuplot 4.6.

EDIT

  1. Writing less times should be sufficient for this.
  2. An example file to produce the plot is available at http://pastebin.com/w0kia7Dt
1
Do you want to spread out the x-axis, or write less of the times? - Tom Fenech
I guess writing less of the times would be better. - evnu
Can you provide a link to your data file (perhaps on pastebin or something similar)? - Tom Fenech
It looks like you found an answer, but this question (stackoverflow.com/questions/15975631/…) might give some ideas for ways to avoid the overlap. - andyras

1 Answers

4
votes

You can use set xtics to mark less points on your x-axis. The first and last argument must be in the same format as your times, in your case %s, or seconds since the UNIX epoch. The middle argument is the number of seconds.

For example, to mark every 8 hours, rather than every 4 as above, you could do something like this:

hours = 8
start = "1393934400"
end = "1394107200"
set xtics start, hours * 3600, end

You can obtain those start and end values using the date command in your terminal

date -d "2014-03-04 08:00" +%s

You could also get them into your script using the gnuplot system command

end = system("date -d '2014-03-06 12:00' +%s")

See help set xtics time_axis for more details.