Plots in multiple scripting languages

Server-side shell scripts are useful for using other scripting languages or command-line programs. Matlab, python, octave, imagemagik, and many other utilities can be used this way. Command-line database queries using mySql or other databases should also be possible. These examples show different ways to plot data from a data file.

Here's the input file (example.dat):

1 5
2 1
4 7
5 9

R

R homepage

t <- read.table("example.dat")
bitmap(file="R_example.png",   type="pngalpha",res=100,height=4,width=4,pointsize=10)
plot(t$V1,t$V2)
dev.off()
RpadDir = gsub("/var/www","",getwd())
cat("<htmlon/><img src='",RpadDir,"/R_example.png'>",sep="")

Yorick (my other favorite interpreted analysis language)

Yorick homepage

#!/usr/bin/yorick -batch

x= y= array(0.,1000) //with yorick, you have to preallocate
//the storage then chop later
n= read(open("example.dat","rt"), x, y)
x= x(:(n/2))
y= y(:(n/2))
window, 0, display="", hcp="t.ps"
plmk, y, x, width=10, msize=.5
limits, .5, 5.5, 0, 9.5
hcp
eps, "t.ps"
$convert t.ps yorick_example.png
RpadDir= cd(".")
RpadDir= strpart(RpadDir,9:strlen(RpadDir))
write, "<htmlon/><img src='",
  RpadDir,
  "yorick_example.png'>", format="%s%s%s"

GRI

GRI homepage

Here's a GRI file:

open example.dat # Open the data file
read columns x y # Read (x,y)
draw curve # Draw data curve
set symbol size 0.2 # 0.2 is radius in cm
draw symbol bullet
draw title "Example 1" # A title for plot
quit

Now we need to run the gri file and convert to something viewable (with Imagemagick):

gri example
convert example.ps gri_example.png
echo '<htmlon/><img src="'
pwd | sed 's/\/var\/www//'
echo '/gri_example.png">'



by Tom Short, tshort@epri.com, Copyright 2005 EPRI, license: GNU GPL v2 or greater