Reputation: 1
So I'm trying to make a plot using pm3d in gnuplot. Unfortunately I seem to run into the problem that the plot is created, with no points or lines on it.
Here is the code for the program that generates the points:
#include<stdio.h>
#include<math.h>
int main() {
double x = -10000;
double y = 0;
double z = 0;
FILE *cool = fopen("coolbeans.txt", "w");
fprintf(cool, "#x\ty\tz\n");
for (int i = 0; 1 < 10000; i++) {
x = x + 10;
y = sqrt(abs(x));
z = -200*(sin(x));
fprintf(cool, "%1.0f\t%f\t%f\n\n", x, y, z);
}
fclose(cool);
return 0;
}
Next I open gnuplot and enter the following commands:
set term jpeg size 3200, 1800
set output 'example.jpg'
splot 'coolbeans.txt' using 1:2:3 with pm3d
I then get this:
Any help would be very much appreciated!
Upvotes: 0
Views: 439
Reputation: 916
I am not sure that why you want to plot that (x,y,z) using pm3d.
Anyway, usual usage of pm3d is as following C program.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int i, j;
int nx = 10, ny = 10;
double dx = 0.1, dy = 0.1;
double x, y, z;
FILE *fp;
if((fp = fopen("output.dat", "w")) == NULL) exit(0);
for(i = 0; i <= nx; i++){
for(j = 0; j <= ny; j++){
x = (double)i*dx;
y = (double)j*dy;
z = sin(2.0*M_PI*x)*cos(2.0*M_PI*y);
fprintf(fp, "%e %e %e\n", x, y, z);
}
fprintf(fp, "\n");
}
fclose(fp);
}
Important point is to input empty row in each loop of x-direction.
Upvotes: 1