带有matplotlib的自定义函数的3d图

问题描述 投票:1回答:1

我需要使用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<---------------

这样我就可以得到成本函数的3d图。

我该怎么做?

python matplotlib 3d
1个回答
0
投票

Matplotlib已经给出了从1d到3d绘制数据的示例,请查阅本教程。

Example Official Matplotlib 3D Plotting

© www.soinside.com 2019 - 2024. All rights reserved.