next up previous
Next: 0.5 LWP Up: 0.4 GNUPlot Basics Previous: 0.4 GNUPlot Basics

0.4.1 Using GNUPlot inside CGI scripts

In this section we will see how we can create a plot inside a CGI script and output the resulting image

[L529guest@biokdd agopu]\$ cat > data_show1
1 0.1
2 0.2
3 0.3
4 0.4
5 0.5
[L529guest@biokdd agopu]\$ cat > data_show2
1 1.1
2 1.2
3 1.3
4 1.4
5 1.5
[L529guest@biokdd agopu]\$ chmod 644 data*

[L529guest@biokdd agopu]\$ cat > plot_show.pl
#!/usr/bin/perl

$|=1;
print "Content-type: text/html\n\n";
 
my $filename="/tmp/anyname". $$. ".png";  # use $$ to make the file name is unique.
umask(022);  # to allow read and execute
print "<img src=\"$filename\">";
 
# remember multiple lines should end with two backslashes, \\
open(G, "|gnuplot") or die "gnuplot failed";
print G <<ENDOFHERE
set term png color medium
set xrange [0:20]
set xlabel "Residue Position"
set ylabel "Relative Entropy"
set output '$filename'
plot 'data_show1' title "Group1" with linespoints, \\
'data2_show' title "Group2" with linespoints
ENDOFHERE

[L529guest@biokdd agopu]\$ chmod 755 *.pl

This is the stuff you can expect to see on your browser if you visit:

http://biokdd.informatics.indiana.edu/cgi-bin/L529guest/agopu/plot_show.pl

(Replace `agopu' with your user name or whatever you named your directory to be. Remove `L529guest' if you are using your own account.)

Figure 6: Screen shot of GNUPlot output when called within a CGI script
\begin{figure}\epsfig{file=images/plot_show.ps, width=16cm}
\end{figure}

Just some notes about the above shown code:


next up previous
Next: 0.5 LWP Up: 0.4 GNUPlot Basics Previous: 0.4 GNUPlot Basics
Arvind Gopu 2006-03-24