Py学习  »  Python

用python绘制带有2个参数的函数的绘图

Алекс Серкин • 7 年前 • 2051 次点击  

我需要为一个区间上定义的简单函数绘制一个图。

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)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43982
文章 [ 1 ]  |  最新文章 7 年前