# python怎么画参数函数图像_用Python绘制带参数的函数图像

def f_standard_normal_distribution(x,u,s):

return math.exp((-(x-u)**2)/2*(s**2))/(math.sqrt(2*math.pi)*s)

x=numpy.linspace(a,b,density)

y=[f_standard_normal_distribution(i,u,s) for i in x]

pyplot.plot(x,y)

pyplot.show()

import matplotlib.pyplot as pyplot

import numpy

import math

def draw_function(a,b,density,u,s):

x=numpy.linspace(a,b,density)

y=[f_standard_normal_distribution(i,u,s) for i in x]

pyplot.plot(x,y)

pyplot.show()

def f_standard_normal_distribution(x,u,s):

return math.exp((-(x-u)**2)/2*(s**2))/(math.sqrt(2*math.pi)*s)

draw_function(-3,3,600,0,1)

1.为了可以将映射方法作为参数传入，将传入draw_function的函数参数改替换数组，并将映射方法传入。def draw_function(a,b,density,f,param):

x=numpy.linspace(a,b,density)

y=[f(i,param) for i in x]

pyplot.plot(x,y)

pyplot.show()

return math.exp((-(x-param[0])**2)/2*(param[1]**2))/(math.sqrt(2*math.pi)*param[1])

2.因为传递参数的数组可能并不符合映射方法的需要，如数组个数少于映射方法需要的参数个数，则会导致异常抛出。因此需在映射方法中对参数数组作出检验。if len(param)!=2:

return 0

import matplotlib.pyplot as pyplot

import numpy

import math

def draw_function(a,b,density,f,param):

x=numpy.linspace(a,b,density)

y=[f(i,param) for i in x]

pyplot.plot(x,y)

pyplot.show()

def f_standard_normal_distribution(x,param):

if len(param)!=2:

return 0

return math.exp((-(x-param[0])**2)/2*(param[1]**2))/(math.sqrt(2*math.pi)*param[1])

draw_function(-3,3,600,f_standard_normal_distribution,[0,1])

11-07 1557
08-26 3864
02-23 1272
03-26 1935
03-01 105