PHYS 252

Getting Started With Gnuplot

Gnuplot is a simple program for displaying and printing graphs.
To get started:

  1. Read Getting Started With Visual C++, in Supplementary Info for Lecture 1.
  2. Make a new project in Visual C++, e.g. with project name mar27b.
  3. Create source file: enter the following example as main.c
    /* Output square and cube */
    #include   <stdio.h>   
    main()                  
    {                               
    	FILE *fp = fopen("out.dat","w") ;  /* opens file "out.dat", with label fp. */
    	                                   /* The "w" means we are going to write to the file */
    	double x  ;     
    	x = -5. ;
    	while (x<5.) {      		   /* loop over x-coordinate as long as x<5 */
    	    fprintf(fp,"%lf %lf %lf\n",x,x*x,x*x*x);    /* output to file square and cube */
    	    x = x + .1;      	  	   /* increase x for next step in loop */
    	}
            fclose(fp) ;       		   /* close file */
    }
    
  4. Create data file "out.dat":
  5. Plot "out.dat" with gnuplot:
  6. Some other useful gnuplot commands:

See also this website or this website for more gnuplot tips