Computational Physics

Dr. Ayars

#!/usr/bin/env python
"""
    A very basic gnuplot example
"""

from math import *                      # used here for trig
import Gnuplot                          # plotting package

x = [z * pi/5.0 for z in range(20)]     # x is now a list of 20 numbers evenly
                                        # spaced from zero to (but not including)
                                        # 4pi.
y = [sin(z) for z in x]                 # y is now sin(x).

g = Gnuplot.Gnuplot(persist=1)          # allows abbreviation.
datapoints = Gnuplot.Data(x,y)
g.title("Sample Plot")
g.xlabel('Angle')
g.ylabel('Value of Sin')
g('set nokey') 
g('set xrange[0:4*pi]')
g.plot(datapoints)