Skip to content

Posts tagged ‘python-gnuplot’

5
Dec

Basic Gnuplot Tutorial – I

This tutorial uses Ubuntu Heron, Python 2.5, python-gnuplot 1.8-1

from Numeric import *
import Gnuplot


g = Gnuplot.Gnuplot()

# generate x, y data to plot
x = arange(10, typecode=Float)
y = x**2

# convert to a form that the gnuplot interface can deal with
d = Gnuplot.Data(x, y, title='data from python')

g.xlabel('x')
g.ylabel('x^2') # looks nice in the postscript

g.plot(d) # actually plot the data

# To Save as postscript. The enhanced=1 is to handle the x^2 in the xlabel.
# Use eps=1 to produce encapsulated postscript.
g.hardcopy('gp_test.ps', enhanced=1, color=1)
raw_input('Saved as gp_test.ps ; please press return to continue...\n')