0
votes

I fail to understand how splot works with points given in a data file. Using the example data from the gnuplot website stored in datafile.dat which is

# The valley of the Gnu.
0 0 10
0 1 10
0 2 10

1 0 10
1 1 5
1 2 10

2 0 10
2 1 1
2 2 10

3 0 10
3 1 0
3 2 10

and running on the command line

$ gnuplot
gnuplot> set xlabel "x"
gnuplot> set ylabel "y"
gnuplot> set zlabel "z"
gnuplot> splot "datafile.dat"

I get this: output

I expected however:

  • the x axis to be in the range 0 to 3 (seems its using the second data column instead)
  • the y axis in the range 0 to 2, not 0 to 3
  • the z axis from the third column in the data file which instead is completely ignored
2

2 Answers

3
votes

In my environment, setting the separator of the data file to a comma, for example, reproduces the phenomenon you are facing.

set datafile separator comma
set xlabel "x"
set ylabel "y"
set zlabel "z"
splot "datafile.dat"

I think it may work if you run the following command right after starting gnuplot, and then run the same commands as in the question.

gnuplot> set datafile separator whitespace

I suspect that your gnuplot, for some reason, has something other than whitespace set as the separator for the datafile.

Make sure which character is set as separator by running the following command.

gnuplot> show datafile separator

And make sure you don't set the set datafile separator in '~/.gnuplot' (on UNIX-like system).

Addition: What was happening

Because the separator was set to a comma, only the first number in each line of your data was read. This is equivalent to the following data.

0
0
0

1
1
1

2
2
2

3
3
3

This data was treated as the equivalent of 4x3 matrix data, based on the number of blocks and the number of rows inside, with the given numbers being interpreted as values on the z-axis.

0 0 0
1 1 1
2 2 2
3 3 3

Drawing this data using splot reproduces the figure in question.

$data <<EOD
0 0 0
1 1 1
2 2 2
3 3 3
EOD

set xlabel "x"
set ylabel "y"
set zlabel "z"
splot $data matrix
0
votes

I'm not sure why you get this result and which columns gnuplot takes as default if you don't specify any.

But check help splot and the examples on the gnuplot homepage and specifiy explitely the columns you want to have plotted:

splot 'datafile.dat' u 1:2:3 with lines

or

splot 'datafile.dat' u 1:2:3 with pm3d