May 22, 2013

Perl & gnuplot for generating graphs

I am going to present here one small script which I use to generate graphs. With small help of perl (to prepare data from text data containing hex values send from sensing board) and gnuplot.

I'll paste here a subroutine to generate a plot file for gnuplot. The subroutine has only one parameter, the file handle to generate a plot file. There's a multiplot with 3 graphs, 2 columns or only one in some cases. Depends on $outfile_name[3]. If there're no data available, only one column is genereated. This could be easily customize to your needs.

I have tweaked it to generate 2 graphs, one is multiplot 5,1 , another one is 3,1. All you have to do before you call this subroutine, prepare your data.



Here's an example of usage, create plt file,close it and call gnuplot.

generate_plot( *PLT );
close PLT;
`$gnuplot $file_name[6]`; #file_name is mine plt file (graph.plt)