This example shows how how to use C gnuplot interface to create simple function plots.

1 #pragma package "../" 2 #include <chterm.h> 3 #include <math.h> 4 #include <chgnuplot.h> 5 6 keyAction_t key(char k) { 7 if (k == 'q' || k == 'Q') { 8 return KEY_QUIT; 9 } else { 10 return KEY_CONTINUE; 11 } 12 } 13 14 int main() 15 { 16 gnuplot_ctrl *handle; 17 handle = gnuplot_init(); 18 19 gnuplot_plot_equation(handle, "sin(x)", "sinus function"); 20 keyboard_loop(key, 200); 21 gnuplot_resetplot(handle); 22 23 gnuplot_setstyle(handle, "lines"); 24 gnuplot_plot_equation(handle, "sin(x)", "sinus function"); 25 keyboard_loop(key, 200); 26 gnuplot_resetplot(handle); 27 28 gnuplot_set_xlabel(handle, "x"); 29 gnuplot_set_ylabel(handle, "f(x)"); 30 gnuplot_setstyle(handle, "impulses"); 31 gnuplot_plot_equation(handle, "sin(x)", "sinus function"); 32 keyboard_loop(key, 200); 33 gnuplot_resetplot(handle); 34 35 gnuplot_set_xlabel(handle, ""); 36 gnuplot_set_ylabel(handle, ""); 37 double x[10] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}; 38 double y[10]; 39 int i; 40 for (i=0; i<10; i++) { 41 y[i] = log(x[i]/0.5); 42 } 43 44 gnuplot_set_xlabel(handle, ""); 45 gnuplot_set_ylabel(handle, ""); 46 gnuplot_cmd(handle, "set pointsize 3"); 47 gnuplot_setstyle(handle, "linespoints"); 48 gnuplot_plot_xy(handle, x, y, 10, "my function"); 49 keyboard_loop(key, 200); 50 gnuplot_resetplot(handle); 51 52 gnuplot_cmd(handle, "splot x*x - y*y"); 53 keyboard_loop(key, 200); 54 return 0; 55 }