Graphics with GLE

From Madagascar
Jump to: navigation, search

The Graphics Layout Engine is a multi-platform open-source package that can create a whole variety of plots from user-defined scripts. It has both very basic drawing primitives and more advanced canvases. It is similar to the vplot core library, with the difference is that plotting templates are saved in script files instead of C programs. Here is an example of a SConstruct drawing a simple 2D analytic function in isometric view: <python> from rsf.proj import *

o1=-2 o2=-2 n1=41 n2=41 d1=0.1 d2=0.1

Flow('cosxpy',None,

   
   math o1=%g o2=%g n1=%d n2=%d d1=%g d2=%g
         output="cos(x1*x1+x2*x2)*exp(-0.1*(x1*x1+x2*x2))"
    % (o1,o2,n1,n2,d1,d2))

Result('cosxpy','grey color=j')

  1. Prepare data for GLE

Flow('cosxpy.z','cosxpy',

   
   disfil number=n col=%d
           header="! nx %d ny %d xmin %g xmax %g ymin %g ymax %g"
    % (n2,n1,n2,o1,o1+(n1-1)*d1,o2,o2+(n2-1)*d2))
  1. Call GLE

Result('cosxpy_iso','cosxpy.gle cosxpy.z',

     
     gle -device pdf -output ${TARGETS[0]} ${SOURCES[0]}
     ,suffix='.pdf',stdin=0,stdout=0)

End() </python> The trick is wrapped into the two last Result() and Flow() statements. The Flow generates a special ASCII file with function values, which will be later used by GLE. The Result actually calls GLE and makes it write a PDF file. The drawing script is contained in another file -- cosxpy.gle , which has a rather simple format:

size 10 10

set font texcmr hei 0.5 just tc

begin surface
    size 10 10
    data "cosxpy.z"
    title "Hat function (3D)"
    xtitle "X-axis" hei 0.4 dist 0.7
    ytitle "Y-axis" hei 0.4 dist 0.7
    ztitle "Z-axis" hei 0.4 dist 0.9
    top color red
    underneath color blue
    base xstep 1 ystep 1
    zaxis min -1.5 max 1.5 hei 0.35
    xaxis hei 0.35 dticks 1
    yaxis hei 0.35 dticks 1
    xlines on
    ylines on
    rotate 45 60 0
end surface

scons lock works just fine and the resulted image is ready to be used in a paper with the regular macros like \plot or \multiplot . The only problem that appears is when scons view is run. It tries to run sfpen to view the resulted PDF file and fails, of course. But other than that, the result (figure below) shows a nice isometric plot, which can be easily reproduced in a regular Madagascar fashion.

GLE example.png