2
votes

I've got data that I want to plot in gnuplot that looks something like this:

1.08 1 4.8
1.53 2 5.9
2.11 3 5.1
2.60 4 6.0

Not that it's terribly important, the first column is the running time of a genetic algorithm, the second column is the generation number, and the third is average fitness.

If I plot it using plot datafile.dat using 1:3 with lines it looks fine, with tics appropriately spaced. However, while I want the x-tics to be labelled with the time, I want the x2-tics to be labelled with the generation number. This is easy to do with plot datafile.dat using 1:3:x2ticlabels(2) with lines, but for the x2-axis it adds a tick for every single line in the data file, instead of automatically choosing an appropriate number of tics.

My full data file has thousands of entries, which results in a solid black line at the top of the graph where the tics would be spaced, and a larger solid black line above where the labels would be placed. Even if I try to manually tell gnuplot how often to place tics on the graph using set x2tics 100 it still displays them for every entry. Is there a way to fix this? Obviously I'd prefer which tics are shown to be automatically chosen, but if I have to do it manually that's fine. The full gnuplot config file is pretty basic, just:

set logscale y 10
set x2tics
plot datafile.dat using 1:3:x2ticlabels(2) with lines
1

1 Answers

1
votes

Here's a solution that will only put a label for every other line in the datafile.

plot 'test.dat' u 1:3:x2ticlabels(int($0)%2==0?stringcolumn(2):'')

One thing that is a little interesting is that the tics don't quite line up with the points. I haven't figured out why yet. With thousands of points, you're probably not likely to notice, but with your example datafile with 4 points, it's noticeable.

Unfortunately, it still draws a tic on the axis for every line in the datafile. set x2tics scale 0 will make those tics go away completely.