将函数和绘图矢量化:
from scipy.integrate import quad
import scipy as sc, numpy as np, math
from scipy import integrate
import matplotlib.pyplot as plt
def integrand(x):
Q_y = (1/(math.sqrt(2*math.pi)))*math.exp((-x**2)/2)
return Q_y
func = np.vectorize(integrand)
x = np.arange(-3, 3, 0.1)
fig = plt.figure()
ax = plt.gca()
y = input('y=')
y = float(y)
result = integrand(y)
x_user = np.arange(y, 3, 0.1)
ax.axvline(y, color='green', lw=2, alpha=0.5)
ax.fill_between(x_user, func(x_user), facecolor="none", hatch="/", edgecolor="red")
ax.annotate('Q({0})={1}'.format(y, round(result, 2)), xy=(0, result), xytext=(0, result))
ax.plot(x, func(x))