當前位置: 首頁>>代碼示例>>Python>>正文


Python Function.computeRange方法代碼示例

本文整理匯總了Python中function.Function.computeRange方法的典型用法代碼示例。如果您正苦於以下問題:Python Function.computeRange方法的具體用法?Python Function.computeRange怎麽用?Python Function.computeRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在function.Function的用法示例。


在下文中一共展示了Function.computeRange方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from function import Function [as 別名]
# 或者: from function.Function import computeRange [as 別名]
def main():
	Maths.generateMathExpressions()
	print("Available operators:")
	for o in Maths.Expressions:
		print(Maths.Expressions[o].getAbbreviation())

	print("-------------------------")
	f = Function("cos(3*x)+6/4*(x+3)", False)
	print("RPN String", f.getRpnString())
	for x in range (2, 11):
		f.compute(x)

	print("-------------------------")

	f = Function("56*((6+2)/(8-x)*2^3", False)
	print("RPN String", f.getRpnString()) #should give 56 6 2 + 8 7 - / 2 3 ^ * *


	mainwindow = MainWindow("Function Drawer", 992, 512)
	fx = f.computeRange(0, 10)
	max_y = max(fx.values())
	min_y = min(fx.values())

	print(min_y, max_y)
	mainwindow.setCoords(-1, min_y, 11, max_y)
	for x in range(0, 11):
		print(fx[x])
		p = Point(x, fx[x])
		p.draw(mainwindow)

	input("Press a key to quit")
開發者ID:feda12,項目名稱:Function-Drawer,代碼行數:33,代碼來源:main.py

示例2: __init__

# 需要導入模塊: from function import Function [as 別名]
# 或者: from function.Function import computeRange [as 別名]
class GraphWidget:
	def __init__(self, pt_left_bot, pt_right_top, win):
		self.function = Function("0")
		self.p1 = pt_left_bot
		self.p2 = pt_right_top
		self.graph_area = Rectangle(self.p1, self.p2)
		self.win = win
		self.accuracy = 0.1
		self.objects_drawn = []

	def getFunction(self):
		return self.func
	def setFunction(self, func):
		self.function = func

	def draw(self, xa, xb):
		self.cleanGraph()
		#Compute function and draw it
		x_min = min(xa, xb)
		x_max = max(xa, xb)
		
		#Compute all the values for f functon, accuracy give the step for computation
		fx = self.function.computeRange(x_min, x_max, self.accuracy)
		y_max = max(fx.values())
		y_min = min(fx.values())
		print(y_max, y_min)
		self.win.setCoords(x_min-(1/10)*x_max, y_min-(1/10)*y_max, x_max+(1/10)*x_max, y_max+(4/10)*y_max)

		x = x_min
		end = x_max
		prevfx = fx[x]
		k = 0
		while x < (end+self.accuracy):
			#p = Point(x, fx)
			#p.draw(mainwindow)
			u = fx[x]
			if k > 0:
				self.drawLine(x-self.accuracy, prevfx, x, u)
			prevfx = u
			x += self.accuracy
			k += 1

		self.drawAxis(x_min, x_max, y_min, y_max)
		


	def drawLine(self, x1, y1, x2, y2):
		l = Line(Point(x1, y1), Point(x2, y2))
		self.objects_drawn.append(l)
		drawer = DrawerThread()
		l.setOutline("blue")
		drawer.run(l, self.win)
		return

	def drawAxis(self, x_min, x_max, y_min, y_max):
		#Draw axes
		#draw x axs first
		#we first consider we will draw it where y=0
		x_axis = Line(Point(x_min, 0), Point(x_max, 0))
		if y_max < 0:
			#if all the x values are under 0
			#then we draw the on the top
			x_axis = Line(Point(x_min, y_max), Point(x_max, y_max))
		elif y_min > 0:
			#if all the x values are over 0
			#then we draw it at the bottom
			x_axis = Line(Point(x_min, y_min), Point(x_max, y_min))
		drawer = DrawerThread()
		drawer.run(x_axis, self.win)
		self.objects_drawn.append(x_axis)

		#we consider we will draw where x=0
		y_axis = Line(Point(0, y_min), Point(0, y_max))
		if x_max < 0:
			#if all the y values are under 0
			#then we draw the on right
			y_axis = Line(Point(x_max, y_min), Point(x_max, y_max))
		elif x_min > 0:
			#if all the y values are over 0
			#then we draw it at the bottom
			y_axis = Line(Point(x_min, y_min), Point(x_min, y_max))
		
		drawer = DrawerThread()
		drawer.run(y_axis, self.win)
		self.objects_drawn.append(y_axis)

		#draw x labels
		y_ax = x_axis.getP1().getY()
		x_step = x_max*(0.1)
		x_size = y_max*.01
		#from 0 to x_max
		x = 0
		togo = x_max+0.1
		while x < togo:
			sign = Line(Point(x, y_ax-x_size), Point(x, y_ax+x_size))
			drawer = DrawerThread()
			drawer.run(sign, self.win)
			self.objects_drawn.append(sign)
			if x != 0:
				text = str(int(x))
#.........這裏部分代碼省略.........
開發者ID:feda12,項目名稱:Function-Drawer,代碼行數:103,代碼來源:graphwidget.py


注:本文中的function.Function.computeRange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。