I don't manage to plot my data with gnuplot when I store it as a binary. Plotting from an ASCII file works without problems. Here's my attempt: First, save the data
// omitted
double *t = alloc_mat(row + 1, col + 1);
for(x = 0; x < row + 1; x++)
for(y = 0; y < col + 1; y++)
if(!y && !x)
t[0] = col + 1;
else if(!x && y != 0)
t[x * (col + 1) + y] = y - 1;
else if(!y && x != 0)
t[x * (col + 1) + y] = x - 1;
else
t[x * (col + 1) + y] = data[(x - 1) * col + y - 1];
writebin_double(fname, t, row + 1, col + 1);
free(t);
The code creates a structure like
N+1, y0, y1, y2, y3, ... yN
x0, z00, z01, z02, z03, ..., z0N
x1, y10, ...
according to http://gnuplot.sourceforge.net/docs_4.2/node330.html#binary_matrix
The function writebin_double is simply
void writebin_double(char *fname, double *data, int row, int col)
{
// omitted
FILE *outfile = fopen(fname, "w");
// omitted
fwrite(data, sizeof(double), row * col, outfile);
fclose(outfile);
}
When trying to plot the data as
set xr [0:599] # an example
set yr [0:799]
splot 'plttmp.dat' binary matrix format='%double' using 1:2:3 w l palette t ''
it fails with "Read grid of zero width" which I don't understand in this case, as the grid is specified in the for loop. I also tried the binary general setting, but it didn't help and I got the same message.
Thanks for ideas!
PS: gnuplot 4.6.4 on Ubuntu 14.04, 64 bit
floatsinstead ofdouble? Possibly theformatoption isn't supported for this kind binary matrices, see also thebinary.csource which is mentioned on the page you linked. - Christophfloatsdoesn't work, it's eitherfloatordouble. In my case, it should read double. I really don't get what I'm doing wrong, since it's just the fact that the data is hold as binary produces this problem. I can provoke an output bysplot '%s' binary format='%double' w pm3dbut it gives me just a couple of weird lines. - Clemensfloatarray in you C-code instead of adoubleone and don't use theformatspecifier at all. - ChristophFile doesn't factorize into full matrix. The plot command I changed tosplot '%s' binary matrix using 1:2:3- Clemenst[0] = col;instead of setting it tocol +1. The example in the documentation might be misleading. There the columns are number from 0 to N, so you have N+1 columns. In your case you havecolcolumns. - Christoph