GracePlot!

A python interface to xmgrace . This module used the grace_np.py module, written by Michael Haggerty, and is built on top of the gracePlot module written by Nathaniel Gray.

I should note that I use python 1.5.2, and Grace-5.1.8.

The end goal of this project is to create a fully functional interface to xmgrace, so that anything you would create or modify in through the GUI could be created or modified by a python script. Currently, xy-plots are almost completely supported with errorbars.  

Here are typical examples of how to use this module:


from GracePlot import *
import math

p=GracePlot()

x=[1,2,3,4,5,6,7,8,9]
y1=map(lambda x:math.sin(x/3.),x)
y2=map(lambda x:math.cos(x/3.),x)

p.plotxy([x,y1],[x,y2])


#A more sophisticated plot can be made using the Data object
from GracePlot import *
p = GracePlot() # A grace session opens

x=[1,2,3,4,5,6,7,8,9,10]
y=[1,2,3,4,5,6,7,8,9,10]

s1=Symbol(symbol=circle,fillcolor=red)
l1=Line(type=none)

d1=Data(x=x,y=y,symbol=s1,line=l1)

p.plot(d1)

p.text('test',.51,.51,color=2)

p.title('Graph Title')

p.yaxis(label=Label('Interesting Ydata',font=2,charsize=1.5))

p.xaxis(label=Label('X axis',font=5,charsize=1.5))


from GracePlot import *
import math

p = GracePlot() # A grace session opens

l1=Line(type=none)


x1=map(lambda x:x/10.,range(0.,100.))
y1=map(math.sin,x1)
y2=map(math.cos,x1)

d2=Data(x=x1,y=y1,
        symbol=Symbol(symbol=circle,fillcolor=red),
        line=l1)
d3=Data(x=x1,y=y2,
        symbol=Symbol(symbol=circle,fillcolor=blue),
        line=l1)

p.plot(d2,d3)

p.xaxis(label=Label('X axis',font=5,charsize=1.5),
        tick=Tick(majorgrid=on,majorlinestyle=dashed,majorcolor=blue,
                  minorgrid=on,minorlinestyle=dotted,minorcolor=blue))
p.yaxis(tick=Tick(majorgrid=on,majorlinestyle=dashed,majorcolor=blue,
                  minorgrid=on,minorlinestyle=dotted,minorcolor=blue))

 

# Here is an example of a plot with error bars on the y-axis
from GracePlot import *
import math
import whrandom

p = GracePlot() # A grace session opens

x=[1,2,3,4,5,6,7,8,9,10]
y=[1,2,3,4,5,6,7,8,9,10]
labels=['pt1','pt2','Iridium','Na','Ti','hydrogen','Mo','Ta','pokemon','digital']

dy=map(lambda x:whrandom.random()*2.,x)

s1=Symbol(symbol=square,fillcolor=cyan)
l1=Line(type=none)

d1=Data(x=x,y=y,dy=dy,symbol=s1,line=l1,type=xydy)

p.plot(d1)

for i in range(len(labels)):
    p.text('  '+labels[i],x[i],y[i],color=violet,charsize=1.2)





You can find the current package at https://sourceforge.net/projects/graceplot/ .

To install it, simply unzip and untar it into a directory called GracePlot somewhere on your python path. There are a few example files included, most of the documentation is in the GracePlot.py file.

I have also included the grace_np.py file, which is required. You may also need to have the Numeric python modules installed, I use a fairly old version, Numeric-17.3.0.

john kitchin




SourceForge Logo