Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

plot

gnuplot

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.

like image 313
K Erlandsson Avatar asked Jan 26 '11 14:01

K Erlandsson


People also ask

How to plot data in gnuplot from file?

To plot functions simply type: plot [function] at the gnuplot> prompt. Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns of numbers.

How do you set x and y axis in gnuplot?

Define a function y=ln(x2). Set the range of x values from -2 to +2 and range of y values from 3 to +3. Show both the axis on the plot. The labels of x axis and y axis be “x values” and “y values” respectively.

What files can gnuplot open?

Gnuplot can read binary data files. However, adequate information about details of the file format must be given on the command line or extracted from the file itself for a supported binary filetype. In particular, there are two structures for binary files, a matrix binary format and a general binary format.

How to run gnuplot?

You can run a script two ways: Type load "scriptname" from within gnuplot. Or, from UNIX, run gnuplot by typing gnuplot scriptname . In this method, gnuplot will exit when your script is finished, so you may want to include PAUSE -1 "Hit any key to continue" as your last line.


1 Answers

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
like image 50
Martin Avatar answered Sep 23 '22 15:09

Martin