123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106openCommonmoduleColor=Simple_color(*****************************************************************************)(* Prelude *)(*****************************************************************************)(* http://www.cs.utk.edu/~plank/plank/jgraph/jgraph.html
*)lettmpfile="/tmp/test.jgr"letprelude()=" newgraph
xaxis
size 7in
min 0
hash 1 mhash 0
(* autogenerated by jgraph.ml *)
"letxaxis_font()="hash_labels hjr font Helvetica fontsize 10 rotate 45"letyaxis_labels=spf"
yaxis
hash_labels fontsize 12 label fontsize 12 : %s
"sletxaxis_labelxposs=spf"
newstring x %d y -4 fontsize 12 : %s
"xposs(*****************************************************************************)(* communicating with a pipe with R seems harder so use R batch mode *)letjgraph_programfile=Common.command2(spf"jgraph %s > %s.ps"filefile)letgv_commandfile=let_status=Unix.system(spf"gv %s.ps &"file)in(* zarb: I need this when I launch the program via eshell, otherwise gv
do not get the chance to be launched
*)Unix.sleep1;()(*****************************************************************************)(* the colomns will be x, the lines will be the y *)letplot_matrix~lines~columns~xlabel~ylabelmatrix=letlimx=List.lengthcolumns-1inletlimy=List.lengthlines-1inCommon.with_open_outfiletmpfile(fun(pr_no_nl,_chan)->letprs=pr_no_nl(s^"\n")inpr(prelude());Common.index_listcolumns|>List.iter(fun(s,i)->pr(spf"hash_label at %d : %s"is););letmiddle=limx/2inpr(xaxis_font());pr(yaxis_labelylabel);pr(xaxis_labelmiddlexlabel);pr"";forj=0tolimydoletcolor=let(r,g,b)=Color.rainbow_colorjinspf"color %f %f %f"rgbinletlbl=List.nthlinesjinpr(spf"newcurve marktype x linetype solid %s label : %s"colorlbl);pr"pts";fori=0tolimxdopr(spf"%d %f"imatrix.(j).(i));donedone);jgraph_programtmpfile;gv_commandtmpfile;()