This is actually a doosie, and I cannot do it without any * nix shell magic.
First we want to get the x tic and ytic tags:
XTICS="`awk 'BEGIN{getline}{printf "%s ",$1}' test.dat`" YTICS="`head -1 test.dat`"
At this point, XTICS is the string "FGH I J", and YTICS is the string "ABCDE".
Now we want to install xtics by iteration:
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) i-1 ) set for [i=1:words(YTICS)] ytics ( word(YTICS,i) i-1 )
We used 2 built-in gnuplot functions ( word
and words
). words(string)
counts how many words are in a given string (a word is a sequence of characters separated by spaces). word(string,n)
returns the nth word in a string.
Now we can build your data file ... The only problem is that matrix
wants to use all the rows and columns in your data file. You may be able to shorten the rows / columns that are really read with the every
keyword, but I donβt know how to do this in matrix files, and I think it might be easier to just rely on shell utilities ( awk
and sed
)
plot "<awk '{$1=\"\"}1' test.dat | sed '1 d'" matrix w image
And now your plot (hopefully) looks the way you want it.
Also note that since we used iteration, this script will only work in gnuplot 4.3 or higher. Since the current stable version is 4.6, I hope that Ok.
source share