问题描述
上周我问了一个问题,关于找到一种从多条曲线(来自多个 Excel 文件的数据)插入曲面的方法,有人向我推荐了一个问题,该问题解释了如何使用 scipy.interpolate.RBFInterpolator (How can I perform two-dimensional interpolation using scipy? ).
我试过这种方法,但我得到了一个糟糕的表面拟合(见下图)。有谁明白我的代码有什么问题?我试图更改内核参数,但“线性”似乎是最好的。我在使用 np.meshgrid 时出错了吗?感谢您的帮助。
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
from scipy.interpolate import RBFInterpolator
fig = plt.figure(figsize=(15,10),dpi=400)
ax = fig.gca(projection='3d')
# List all the results files in the folder (here 'Sress_Strain') to plot them.
results_list = os.listdir(r"C:/Users/bdhugu/Desktop/Strain_Stress")
for i in range(len(results_list)):
if i == 0:
results = pd.read_excel(r"C:/Users/bdhugu/Desktop/Strain_Stress/"+results_list[i])
strain = results["Strain (mm/mm)"]
stress = results["Stress (MPa)"]
strain_rate = results["Strain rate (s^-1)"]
if i>0:
new_results = pd.read_excel(r"C:/Users/bdhugu/Desktop/Strain_Stress/"+results_list[i])
new_strain = new_results["Strain (mm/mm)"]
new_stress = new_results["Stress (MPa)"]
new_strain_rate = new_results["Strain rate (s^-1)"]
strain = strain.append(new_strain,ignore_index=False)
stress = stress.append(new_stress,ignore_index=False)
strain_rate = strain_rate.append(new_strain_rate,ignore_index=False)
# RBFINTERPOLATOR METHOD
# ----------------------------------------------------------------------------
x_scattered = strain
y_scattered = strain_rate
z_scattered = stress
scattered_points = np.stack([x_scattered.ravel(),y_scattered.ravel()],-1)
x_dense,y_dense = np.meshgrid(np.linspace(min(strain),max(strain),20),np.linspace(min(strain_rate),max(strain_rate),21))
dense_points = np.stack([x_dense.ravel(),y_dense.ravel()],-1)
interpolation = RBFInterpolator(scattered_points,z_scattered.ravel(),smoothing = 0,kernel='linear',epsilon=1,degree=0)
z_dense = interpolation(dense_points).reshape(x_dense.shape)
fig = plt.figure(figsize=(15,dpi=400)
ax = plt.axes(projection='3d')
ax.plot_surface(x_dense,y_dense,z_dense,cmap='viridis',edgecolor='none')
ax.invert_xaxis()
ax.set_title('Surface plot')
plt.show()
Surface fitting with RBFInterpolator
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)