3

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.

2
  • Have you tried simply plotting plot "file.bin" binary to see if that works? Commented Jul 18, 2016 at 14:40
  • yes I've tried and didn't work. It says "Read grid of zero width" Commented Jul 18, 2016 at 15:15

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

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.