2014-04-06 82 views
0

所以我试图在gnuplot中使用pm3d进行绘图。不幸的是,我似乎遇到了这样一个问题,即情节是创建的,没有点或线。gnuplot pm3d没有绘图点

这里是产生点为程序代码:

#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; 
} 

接下来,我打开gnuplot的,然后输入以下命令:

set term jpeg size 3200, 1800 
set output 'example.jpg' 
splot 'coolbeans.txt' using 1:2:3 with pm3d 

然后我得到这个:

enter image description here

任何帮助将非常感谢!

回答

1

我不确定你为什么要用pm3d绘制(x,y,z)。

无论如何,pm3d的常用用法如下C程序。

#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); 
} 

重要的一点是在x方向的每个循环中输入空行。

+0

Ohhhhh,非常感谢你设置这个直线!现在变得更有意义:) – Ben