我需要为一个区间上定义的简单函数绘制一个图。
import numpy as np
from matplotlib import pylab as plt
def sqr(x, n=2):
return float(x ** n)
def get_plot(func, xs, n):
ys = []
for x in xs:
ys.append(func(x, n))
ys = np.array(ys)
plt.plot(xs, ys)
xs = np.arange(1.0, 30., 0.01)
get_plot(sqr, xs, 4)
但它给了我类型错误:
TypeError: get_plot() takes exactly 2 arguments (3 given)