How to pass gnuplot a matrix and splot pm3d map in c? -
How to pass gnuplot a matrix and splot pm3d map in c? -
so, time, have matrix called zvalue[10][10], , draw pm3d map, normal x-y grids, , zvalue[i][j] value of point (i,j).
in gnuplot, use:
set pm3d map splot zvalue matrix using 1:2:3 pm3d and in c++ gnuplot pipes, can utilize function gp.file1d() accomplish this.
gp << "splot" << gp.file1d(matrix) << "matrix using 2:1:3" << "with pm3d\n" but now, in c gnuplot pipe, of course of study can write matrix file called zvalue.txt, , utilize following:
fprintf(gp, "splot \"zvalue.txt\" matrix using 1:2:3 pm3d\n") but there other way? tried @christ's suggestion when deal normal splot matrix, like:
int main(void) { file *gp = popen(gnuplot, "w"); fprintf(gp, "splot '-' matrix using 1:2:3\n"); int i, j; (i = 0; < 10; i++) { (j = 0; j < 10; j++) fprintf(gp, "%d ", i*j); fprintf(gp, "\n"); } pclose(gp); homecoming 0; } but when it's pm3d, not work well. tried splot point point, works nomal splot matrix, here pm3d, nil works.
the next script works fine pm3d:
#include <stdio.h> #define gnuplot "gnuplot -persist" int main(void) { file *gp = popen(gnuplot, "w"); fprintf(gp, "set pm3d map\n"); fprintf(gp, "splot '-' matrix using 1:2:3 pm3d\n"); int i, j; (i = 0; < 10; i++) { (j = 0; j < 10; j++) fprintf(gp, "%d ", i*j); fprintf(gp, "\n"); } pclose(gp); homecoming 0; } so if have programme makes utilize of pm3d , doesn't work, help see that total file (so 1 can copy&paste code compile , test it).
matrix gnuplot
Comments
Post a Comment