代码拉取完成,页面将自动刷新
import matplotlib.pyplot as plt
import os
from interpolation import *
from frozen_dir import app_path
def plot_and_save(x, y, target_x, result, method, times):
x = np.array(x, dtype=float)
x = np.append(x, target_x)
min_x = x[np.argmin(x)]
max_x = x[np.argmax(x)]
x = np.delete(x, len(x)-1)
y = np.array(y, dtype=float)
target_x = float(target_x)
result = float(result)
plt.figure()
plt.scatter(x, y, c='r', marker='o', s=20, label='Original')
plt.scatter(target_x, result, c='b', marker='x', s=30, label='Target')
x_line = np.arange(min_x, max_x, (max_x - min_x) / 1000)
y_line = np.zeros(len(x_line))
if method == "Newton":
plt.title("Inerpolation-Newton")
for i in range(len(x_line)):
y_line[i] = newton(list(x), list(y), float(x_line[i]))
elif method == "Lagrange":
plt.title("Inerpolation-Lagrange")
for i in range(len(x_line)):
y_line[i] = lagrange(list(x), list(y), float(x_line[i]))
plt.plot(x_line, y_line, c='g', label='Line')
plt.legend()
if not os.path.exists(os.path.join(app_path(), "tmpresults")):
os.mkdir(os.path.join(app_path(), "tmpresults"))
plt.savefig(os.path.join(app_path(), "tmpresults\\" + str(times) + ".png"), bbox_inches='tight')
def plot_and_save_forCubic(x, y, target_x, result, X_range, Y_res, times):
plt.figure()
plt.scatter(x, y, c='r', marker='o', s=20, label='Original')
plt.scatter(target_x, result, c='b', marker='x', s=30, label='Target')
plt.plot(X_range, Y_res, c='g', label='line')
plt.legend()
plt.title("Inerpolation-Cubic")
if not os.path.exists(os.path.join(app_path(), "tmpresults")):
os.mkdir(os.path.join(app_path(), "tmpresults"))
plt.savefig(os.path.join(app_path(), "tmpresults\\" + str(times) + ".png"), bbox_inches='tight')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。