我正在尝试绘制以下函数的输出。函数本身将计算给定参数的概率密度。该图应呈正态分布的钟形,但不一定对称。我该如何绘制?有什么建议吗?
我尝试使用plt.plot(x,y,'b')进行绘制,但这不起作用。
import math
import numpy as np
from scipy import fftpack
from scipy.special import gamma
import matplotlib.pyplot as plt
u=1
T=1
N=4096
du=0.001534
dt=0.001
mu=0.5
eta=0.25
args=(5,30,35,0.5)
scale=1
#### 1.1 Defining the parameters of the model
def cf_log_cgmy(u, lnS, T, mu ,half_etasq, C, G, M, Y):
omega = -C*gamma(-Y)*(np.power(M-1,Y)-np.power(M,Y)+np.power(G+1,Y)-np.power(G,Y ))
phi_CGMY = C*T*gamma(-Y)*(np.power(M-1j*u,Y)-np.power(M,Y)+np.power(G+1j*u,Y)- np.power(G,Y))
phi = 1j*u*(lnS + (mu+omega-half_etasq)*T) + phi_CGMY - half_etasq*np.power(u,2)
return np.exp(scale*phi)
#### 1.2 From the characteristic function to the probability density function
def cf_to_pdf(cf,du,N):
vec = np.linspace(0,N-1,N)
u = du* (vec-N/2)
res = np.fft.ifftshift(fftpack.fft(np.fft.fftshift(cf(u))))
x = np.linspace(-(np.pi)/du,(np.pi)/du,N, endpoint=False)
y = np.real(res*du/(2*np.pi))
return x , y
def dist_cgmy(args, du, N, dt,mu, eta):
cf = lambda u: cf_log_cgmy(u,0,dt,mu,0.5*np.power(eta,2),args[0],args[1],args[2],args[3])
return cf_to_pdf(cf ,du ,N)
dist_cgmy(args, du, N, dt,mu, eta)
## The output is below
(array([-2047.97435045, -2046.97436297, -2045.9743755 , ...,
2044.97438802, 2045.9743755 , 2046.97436297]),
array([-2.70244620e-08, 2.68320697e-08, -2.66397090e-08, ...,
2.76018306e-08, -2.74093422e-08, 2.72168861e-08]))