Search code examples
plotgnuplotbinaryfiles

plot single column binary file with gnuplot


how can I plot single column binary file with gnuplot?

This is the gnuplot command I am using:

plot "file.bin" binary format="%float" u ($0+1):1 every ::0::999

but I get all the points along the vertical line x = 0.

I am creatiing the binary file in a C code I have:

write(fdesc, bin_data, tot_size * sizeof(double));

Thanks.


Solution

  • If you write double values to the binary file, you must also read doubles from gnuplot:

    plot "file.bin" binary format="%double" u 0:1 every ::::999
    

    As a more complete example, consider the following C snippet simple.c:

    #include <unistd.h>    
    int main(int argc, char* argv[])
    {
        const int N = 128;
        double values[N];
        int i;
        for (i = 0; i < N; i++)
        values[i] = i * i;
    
        write(STDOUT_FILENO, values, N*sizeof(double));
    }
    

    Compile that with gcc simple.c, open gnuplot and type

    plot '< ./a.out' binary format='%double' using 0:1