2
votes

I have data file of the form:

unimportant1      unimportant2    unimportant3     matrixdata[i]
1e4               2e5             3e2              1 2 3 4 5
2e3               1e1             7e3              5 4 3 2 1
...               ...             ...              ...
2e3               1e4             4e2              4 4 4 4 4

So it has columnheaders (here "unimportant1" to "unimportant3") as the first row. I want gnuplot to ignore these first three unimportant columns columns so the data entries in exponential notation. I want gnuplot to plot the matrixdata as a matrix. So as if I did it like this:

#!/usr/bin/gnuplot -p

plot '-' matrix with image
1 2 3 4 5
5 4 3 2 1
...
4 4 4 4 4

e

How do I get gnuplot to ignore the first three columns and the header row and plot the rest as matrix image? For compatibility, I would prefere a gnuplot built-in to do that, but I could write a shell script and use the `plot '< ...' syntax preprocessing the data file.

Edit: So neuhaus' answer almost solved it. The only thing I'm missing is, how to ignore the first row (line) with the text header data. Every seems to expect numeric data and so the whole plot fails as it's not a matrix. I don't want to comment out the fist line, as I'm using the unimportant data sets for other 2D plots that, in turn, use the header data.

So how do I skip a row in a matrix plot that already uses every to skip columns?

3
Unfortunately not a solution, but an outlook to a possible solution: Gnuplot 5.0 has a skip option, which unfortunately works only without matrix: plot 'data.dat' skip 1 with lines. But I would consider this a bug, for me plot 'matrix.dat' matrix every ::3 skip 1 with image should work... A very ugly and fragile hack would be to use set datafile commentschar 'u'; plot 'matrix.dat' matrix every ::3 with image.Christoph
Commenting out the first line with a # would make things very much simpler.Joce

3 Answers

2
votes

When using matrix gnuplot must first parse the data file before it can skip rows and columns. Now, your first row evaluates to four invalid number, the second row has 8 number and I get an error that Matrix does not represent a grid.

If you don't want to comment out the first line or skip it with an external tool like < tail -n +2 matrix.dat, then you could change it to contain some dummy strings like

unimportant1      unimportant2    unimportant3     matrixdata[i] B C D E
1e4               2e5             3e2              1 2 3 4 5
2e3               1e1             7e3              5 4 3 2 1
...               ...             ...              ...
2e3               1e4             4e2              4 4 4 4 4

Now your first row has as many entries as the other rows, and you can plot this file with

plot 'test.txt' matrix every ::3:1 with image

This still gives you a warning: matrix contains missing or undefined values, but you don't need to care.

2
votes

I'm not familiar with matrix plots, but I got some sample data and

plot 'matrix.dat' matrix every ::3 with image

seems to do the trick.

0
votes

You could probably use shell commands, for instance, the following skips the first six lines of a file:

plot '<tail -n +7 terrain0.dem' matrix with image