1
votes

As the title says, I want to control the range and the amount of xtics. I use gnuplot for plotting data files in which the horizontal axes is usually time (t) taking values in the interval [0, t_max]. OK, now let's suppose the following scenario:

The maximum value of time is 4086 and this particular value is not known beforehand. However, it can be found using

stats "data.out" u 1
set xrange [0:STATS_max]

My question is how can I round up the maximum value of t to the closest hundred (4100 in this case)? Also, is there a way to tell gnuplot to print only 5 ticks at the horizontal axes regardless of its range (rounding up the maximum value to the closest hundred, or decade it will always be divided by 5)?

Many thanks in advance!

1

1 Answers

1
votes

To round up to the closest hundred, just use the ceil function:

set xrange[0: 100*ceil(STATS_max/100.0)]

Regarding the xtics, you can only set the start, increment, end, and explicit tic position of the tics, but not the number of ticks. But since you set the xrange manually, you can use this information to calculate the tic frequency:

x_lim = 100*ceil(STATS_max/100.0)
set xrange[0: x_lim]
set xtics x_lim/4.0