将3D表面拟合到线条

时间:2017-07-18 21:23:10

标签: python numpy data-fitting

我正在尝试将3D表面贴合到我所拥有的十几条线上,并且我不确定如何做到这一点。以下是我到目前为止的情况:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

healths = [80, 55, 17, 74, 57, 31, 22, 27, 87, 18, 43]
models = [np.poly1d([  4.28223697e+08,  -3.83982829e+09,   1.54420366e+10,
        -3.68735527e+10,   5.82979362e+10,  -6.43887895e+10,
         5.10598512e+10,  -2.94075941e+10,   1.22979001e+10,
        -3.69415039e+09,   7.80163678e+08,  -1.12121998e+08,
         1.05309654e+07,  -6.30329783e+05,   2.62939411e+04,
         2.78341012e+03]),
          np.poly1d([ -5.03569457e+08,   4.13162720e+09,  -1.53435594e+10,
         3.41117449e+10,  -5.05920921e+10,   5.27923363e+10,
        -3.98217265e+10,   2.19550281e+10,  -8.83588557e+09,
         2.56102119e+09,  -5.19347600e+08,   6.97912073e+07,
        -5.55518569e+06,   1.81867166e+05,   6.20639376e+03,
         2.98402109e+03]),
          np.poly1d([ -3.11228639e+08,   2.54546572e+09,  -9.38149455e+09,
         2.05935433e+10,  -2.99744015e+10,   3.04666739e+10,
        -2.21712463e+10,   1.16419022e+10,  -4.38122091e+09,
         1.15421540e+09,  -2.02321433e+08,   2.09660556e+07,
        -7.91107187e+05,  -7.20219187e+04,   1.09687645e+04,
         3.03857181e+03]),
          np.poly1d([  4.06376109e+08,  -3.40876838e+09,   1.29871912e+10,
        -2.97061518e+10,   4.54326091e+10,  -4.89753710e+10,
         3.82216169e+10,  -2.18390890e+10,   9.13394309e+09,
        -2.76751311e+09,   5.95043272e+08,  -8.79507913e+07,
         8.57795062e+06,  -5.35644516e+05,   2.33340505e+04,
         2.84100399e+03]),
          np.poly1d([  5.85452053e+08,  -4.32915850e+09,   1.44085701e+10,
        -2.85267351e+10,   3.74193127e+10,  -3.42989241e+10,
         2.26027183e+10,  -1.08749153e+10,   3.85568236e+09,
        -1.01690647e+09,   2.02670602e+08,  -3.11739277e+07,
         3.71627668e+06,  -3.28017937e+05,   2.02386281e+04,
         2.86613920e+03]),
          np.poly1d([  9.67869416e+07,  -7.20947000e+08,   2.42488924e+09,
        -4.85195211e+09,   6.39741251e+09,  -5.80880723e+09,
         3.67879424e+09,  -1.60522563e+09,   4.62972701e+08,
        -8.12821951e+07,   8.28251991e+06,  -1.33038835e+06,
         5.02616864e+05,  -1.06915704e+05,   1.18577216e+04,
         2.95626138e+03]),
          np.poly1d([ -8.21965398e+07,   6.66113115e+08,  -2.43997814e+09,
         5.35210028e+09,  -7.84838350e+09,   8.12834471e+09,
        -6.11475052e+09,   3.37560830e+09,  -1.35904117e+09,
         3.88270096e+08,  -7.36513971e+07,   7.69475814e+06,
        -4.68518014e+04,  -9.39497975e+04,   1.19806651e+04,
         2.94753388e+03]),
          np.poly1d([  4.44955719e+06,  -4.77598603e+07,   2.22221359e+08,
        -6.00377966e+08,   1.05765733e+09,  -1.28774804e+09,
         1.11742436e+09,  -7.01168814e+08,   3.19423895e+08,
        -1.05427538e+08,   2.51936455e+07,  -4.42976358e+06,
         6.05534885e+05,  -7.03349132e+04,   7.68758833e+03,
         3.07576987e+03]),
          np.poly1d([  1.86261524e+09,  -1.48587084e+10,   5.35778935e+10,
        -1.15449514e+11,   1.65600547e+11,  -1.66711318e+11,
         1.21000328e+11,  -6.40359773e+10,   2.47042057e+10,
        -6.87497940e+09,   1.35135140e+09,  -1.81534762e+08,
         1.59351750e+07,  -8.74063407e+05,   3.12551420e+04,
         2.78842491e+03]),
          np.poly1d([ -5.18981082e+08,   4.15882351e+09,  -1.50353149e+10,
         3.24186114e+10,  -4.64249139e+10,   4.65234117e+10,
        -3.34717498e+10,   1.74414418e+10,  -6.54853332e+09,
         1.73539847e+09,  -3.10545763e+08,   3.40774866e+07,
        -1.68331576e+06,  -5.34555987e+04,   1.21777897e+04,
         2.98675915e+03]),
          np.poly1d([ -2.06268790e+08,   1.62871951e+09,  -5.84473299e+09,
         1.26039508e+10,  -1.81881671e+10,   1.84965039e+10,
        -1.35835529e+10,   7.25000855e+09,  -2.78509188e+09,
         7.47231759e+08,  -1.30834535e+08,   1.24172387e+07,
        -7.93649306e+04,  -1.15924911e+05,   1.29540492e+04,
         2.97883998e+03])]

x = np.linspace(0,1,1000)
y = [[health]*1000 for health in healths]
z = [model(x) for model in models]

# Plot all the lines I want to fit a surface to
fig1 = plt.figure()
ax1 = fig1.add_subplot(111, projection='3d')
for yy, zz in zip(y, z):
    ax1.plot(x, yy, zz)

ax1.set_xlabel('SoC')
ax1.set_ylabel('SoH')
ax1.set_zlabel('OCV')

#Create many small surfaces (FOUND ON SO)
def fun(x, y):
  return models[healths.index(y)](x) # Select the model for the correct health, and evaluate at all x points

y = healths
X, Y = np.meshgrid(x, y)
zs = np.array([fun(x,y) for x,y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
# end of what was found on SO

# Plot the surface
fig2 = plt.figure()
ax2 = fig2.add_subplot(111, projection='3d')

ax2.plot_surface(X, Y, Z)

ax2.set_xlabel('SoC')
ax2.set_ylabel('SoH')
ax2.set_zlabel('OCV')

plt.show()

给出以下图表: Lines to fit Many surfaces plotted together

但是这有一些问题。

  1. 这似乎只是一组被绘制的小表面,而不是一个适合所有留置的单个表面
  2. 我没有得到一个可以用来重现表面的公式(与np.poly1d不同)
  3. 我尝试这样做的原因是因为我希望能够仅输入health值(绘图上的SoH),然后输出类似于我想要的2d线。

    为了做到这一点,我相信我需要在线条上安装3D表面。所以,我的问题是,如何将3D曲面拟合到线条并获得曲面方程?

    谢谢,如果有人需要更多详细信息或者是否已经回答,请与我们联系。我在网上寻找了一段时间,找不到我能做的工作的答案。

0 个答案:

没有答案