2

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?

2
  • 1
    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. Commented Jan 29, 2015 at 15:25
  • Commenting out the first line with a # would make things very much simpler. Commented Jun 21, 2016 at 21:18

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

6 Comments

This is true for a regular plot, but not for matrix data. Sorry.
I might be mistaken, but if you read closely plot 'a.dat' using 1:3 will only plot a 2D curve of the x-coordinate and the z value there. Not a pixelmap of all matrix entries. The start end end in every refer to the row only, not the column.
That seems to work for the column skipping. I guess something similar will skip the first row. Thank you!
Then I get "warning: matrix contains missing or undefined values. Matrix does not represent a grid". Did you test ::3:1 with text data in the first row as in my example data sheet?
Yes. I get the same warning, but the image looks ok.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.