Created
October 1, 2019 05:00
-
-
Save LoboLofi/a1b04a41c4465dbcb5a49b56af53c978 to your computer and use it in GitHub Desktop.
A snipet to plot whatever function in R2 that depends of some constant A. Have a three examples, have a lot of issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from mpl_toolkits.mplot3d import Axes3D | |
| from matplotlib.legend_handler import HandlerLine2D | |
| import matplotlib.pyplot as plt | |
| import math | |
| def drange(start, stop, step): | |
| r = start | |
| while r < stop: | |
| yield r | |
| r += step | |
| def ArrFunction(f,beg, end, step, const): | |
| return [f(const,r) for r in drange(beg,end,step)] | |
| def VaryGraph(rango,funcion,textF, rangoinit = 0): | |
| data = [(ArrFunction(funcion, -10, 10, 0.1,n), n) for n in range(rangoinit, rango)] | |
| for i in range(len(data)): | |
| aux, = plt.plot(data[i][0], label='a = '+str(data[i][1]) ) | |
| plt.legend(handler_map={aux: HandlerLine2D(numpoints=3)}) | |
| plt.ylabel("f(x)="+textF) | |
| plt.xlabel("f(x)") | |
| plt.show() | |
| def wave(a,x): | |
| return a*math.sin(x)+a+x*2 | |
| def Fwave(a,x): | |
| y= 0 | |
| for i in drange(1,a,0.3): | |
| y += math.sin( x*math.pi*i )/i | |
| y *= (4/math.pi) | |
| return y | |
| def PolyPoy(a,x): | |
| return a*(x*x+a*x) | |
| VaryGraph(10,Fwave,"a*(x*x+a*x)") | |
| VaryGraph(10,wave,"a*(x*x+a*x)") | |
| VaryGraph(10,lambda a,x: (a)*(x*x+a*x) ,"a*(x*x+a*x)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment