I'm trying to make a simple plotting function plot2d
,
def plot2d(xmin,xmax,func):
x=np.linspace(xmin, xmax, num=50)
plt.plot(x,func)
plt.show()
The idea is you input the variable 'func' in terms of x, like x**2.
edit* Here's the error:
>>> plot2d(-10,10, x**2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
edit** I think the issue was that when you first call the function the linspace x hasn't be created yet. This worked:
import numpy as np
import matplotlib.pyplot as plt
def plot2d(xmin,xmax):
x=np.linspace(xmin, xmax, num=50)
func=input('Define fucntion: ')
plt.plot(x,func)
plt.show()