I am trying to make a heatmap of values in polar coordinates using gnuplot
. I found this SO question, which seems to indicate that I need to use splot
and pm3d
, and feed it the points in rectangular form. Ideally, I would like to pipe the data into gnuplot
from another program without converting to ASCII or use a temporary file, so I have been trying to get it to read from a binary format.
To generate some test data:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
FILE *out = fopen("test.bin", "wb");
for(int i=0; i<100; i++) {
float output[3];
float r = (float)rand()/RAND_MAX;
float theta = (float)rand()/RAND_MAX * 2*M_PI;
output[0] = r*cos(theta);
output[1] = r*sin(theta);
output[2] = r*r;
fwrite(output, sizeof(float), 3, out);
}
fclose(out);
}
This makes data in the format
X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3 ...
Reading the gnuplot
docs, it seems to prefer data in a matrix format with column and row headers, which is incompatible with conversion from polar (since no x and y coordinates are the same), and I can't decipher what it's saying past that. After messing around for a while the best I have gotten is this:
splot 'test.bin' binary record=(100):(100):(100)
How can I convert this into a 2D heatmap plot, where the outside is "brighter" than the middle like this?
Attempting to use pm3d
just results in the following error:
gnuplot> splot 'test.bin' binary record=(100):(100):(100) w pm3d
Warning: Single isoline (scan) is not enough for a pm3d plot.
Hint: Missing blank lines in the data file? See 'help pm3d' and FAQ.