我需要用python做一个3d图。在文档中没有我可以使用的示例。
这是我的代码:
f0=interp1d(t1,sig1,kind="cubic",bounds_error=False,fill_value=0)
g0=interp1d(t1,sig2,kind="cubic",bounds_error=False,fill_value=0)
""" Linear example """
A=5.
B=1.1
C=0
I=arange(t1.min(),t1.max(),1)
# g(t) and f1(t) are the periodical extension of f0 and g0
def s(t):
return A+B*t+C*t*t
def g(t):
M=g0.x.max()
m=g0.x.min()
t=t+m
t=t%M
return g0(t)
def f1(t):
M=f0.x.max()
m=g0.x.min()
t=t+m
t=t%M
return f0(t)
# f(t) is the shifted version of f1(t).
def f(t):
return f1(s(t))
# This is the cost function that we are trying to minimize
def cost(x):
b=x[0]
a=x[1]
return norm(g(b*I+a)-f(I))
I2=array([s(t) for t in I]) # the interval defined by s(t)
aa=arange(A,A+10,0.5)
bb=arange(-1.5*B,1.5*B,0.1)
plot3d(aa,bb,cost) # This is what I would like<---------------
这样我就可以得到成本函数的三维图。
我该怎么做?