Making x-axis tics from column in data file in Gnuplot

K Erlandsson picture K Erlandsson · Jan 26, 2011 · Viewed 23.7k times · Source

I have a data file in the following format.

/foo.jsp 1234
/bar.jsp 6653
/foobar.jsp 9986
/bar.jsp 2221
/foo.jsp 5643

I want to plot this file in Gnuplot where the tics on the x axis is taken from the first column and the values on the y axis from the second column. To illustrate I would like the chart to look something like this:

10000    x           x
5000     x           x          x
0      /foo.jsp /bar.jsp /foobar.jsp

Where the x's are the points in the chart.

The best I have managed to do is:

plot "datafile.dat" using 2:xticlabel(1) with points

However, that command repeats the tics for each value in the first column (i.e. I get two /foo.jsp tics on the x axis). I would like there to be one unique tic for each unique string in the first column.

Answer

Martin picture Martin · Jan 26, 2011

I think you should include a column with just the x number, say foo.jsp=1 , bar.jsp=2, etc. and suppose you put this in the first column.

So your datafile would look like:

1 foo.jsp 1234
2 bar.jsp 6653
3 foobar.jsp 9986
2 bar.jsp 2221
1 foo.jsp 5643

Then use:

plot "datafile.dat" using 1:3:xtic(2) with points