Aditya Vijaykumar
Aditya Vijaykumar

Reputation: 21

Formatting data file to plot as pm3d map in gnuplot

I have a three column data file generated from a python script after some simulation. It has two parameters in the first two columns, and value of a function in the third. I read up that the data column should be in a specific format to input into pm3d in gnuplot. Is there a shortcut to format the data file into the pm3d format? (a blank line after every change in x value). Though my data points are evenly spaced, the data is all mixed up, so I am finding formatting a bit tough. Please help.

Example file

1 2 3
2 6 5
1 1 8
2 5 3

(original file has > 40000 lines)

Upvotes: 1

Views: 1746

Answers (1)

ewcz
ewcz

Reputation: 13087

Indeed, as the Gnuplot FAQ mentions in 3.9, one needs a blank line after every change in the x-coordinate. It even recommends a gawk script to perform this "transformation". If your data is, as you say, mixed up, you might want to sort it first and then apply the mentioned script.

Assuming that the gawk script addblanks.awk contains:

/^[[:blank:]]*#/ {next} # ignore comments (lines starting with #)
NF < 3 {next} # ignore lines which don't have at least 3 columns
$1 != prev {printf "\n"; prev=$1} # print blank line
{print} # print the line

and your data file is, e.g., input.dat, then

sort -k1,1g -k2,2g input.dat | gawk -f addblanks.awk

produces

1 1 8
1 2 3

2 5 3
2 6 5

Upvotes: 1

Related Questions