File: plotfunc.py

package info (click to toggle)
swig 1.1p5-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 9,448 kB
  • ctags: 5,025
  • sloc: cpp: 21,599; ansic: 13,333; yacc: 3,297; python: 2,794; makefile: 2,197; perl: 1,984; tcl: 1,583; sh: 736; lisp: 201; objc: 143
file content (35 lines) | stat: -rw-r--r-- 782 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Class to plot a simple mathematical function

from image2d import *

class PlotFunc(Image2D):
	def __init__(self,func,xmin,ymin,xmax,ymax,npoints=100):
		Image2D.__init__(self,xmin,ymin,xmax,ymax)
		self.symbol = None
		self.color = YELLOW
		self.func = func
		self.npoints = npoints
	def draw(self):
		pts = []
		dx = 1.0*(self.xmax-self.xmin)/self.npoints
		x = self.xmin
		for i in xrange(0,self.npoints):
			pts.append(self.func(x))
			x = x + dx
		self.newplot()
		self.plotarray(pts,self.xmin,self.xmax,self.color,self.symbol)



# Sample code

import math

p = PlotFunc(lambda x: 0.5*math.sin(x)+0.75*math.sin(2*x)-0.6*math.sin(3*x),-10,-2,10,2,200)
p.symbol = TRIANGLE
p.xaxis_label = "X"
p.yaxis_label = "Y"
p.xtick_spacing = 3.14159265/2
p.ytick_spacing = 0.5
p.show()