1、置信区间的求法(平均值、标准差、正态分布),可以参考如下网站:
https://www.omnicalculator.com/statistics/confidence-interval#what-is-the-confidence-interval
python代码

2、椭圆误差怎么画?(定义长轴、短轴、旋转角、中心坐标点)

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from matplotlib.patches import Ellipse
from scipy.spatial.transform import Rotation as R
# Given latitude and longitude data
data = np.array([
[101.8920721, 32.2139640],
[101.9100901, 32.2680180],
[101.7839640, 32.1959459],
[101.9010811, 32.2229730],
[101.9100901, 32.2409910],
[101.7569369, 32.2860360],
[101.7659459, 32.2950450],
[101.7479279, 32.2319820],
[101.7929730, 32.3130631],
[101.8830631, 32.2049550],
[101.8650450, 32.1959459],
[101.8200000, 32.1869369],
[101.9100901, 32.2770270],
[101.8740541, 32.3130631],
[101.8109910, 32.1869369],
[101.7659459, 32.2049550],
[101.7749550, 32.3040541],
[101.7569369, 32.2139640],
[101.8290090, 32.1869369],
[101.7479279, 32.2770270],
[101.8290090, 32.3220721],
[101.8380180, 32.3220721],
[101.9010811, 32.2950450],
[101.8920721, 32.3040541],
[101.9100901, 32.2319820]
])
# Define ellipse equation
def ellipse_eq(x, xc, yc, a, b, theta):
# Rotation matrix
R_theta = R.from_euler('z', theta, degrees=True).as_matrix()
# Coordinates relative to the center
x_rel = x - np.array([xc, yc])
# Rotate the coordinates
x_rotated = np.dot(R_theta[:2, :2], x_rel.T).T
# Equation of the rotated ellipse
return ((x_rotated[:, 0]) ** 2) / a ** 2 + ((x_rotated[:, 1]) ** 2) / b ** 2
# Fit ellipse
initial_guess = [np.mean(data[:, 0]), np.mean(data[:, 1]), np.std(data[:, 0]), np.std(data[:, 1]), 0]
popt, _ = curve_fit(ellipse_eq, data, np.ones(data.shape[0]), p0=initial_guess)
# Extract ellipse parameters
xc, yc, a, b, theta = popt
print(xc,yc,a,b,theta)
# Calculate points on the ellipse
angles = np.arange(0, 2*np.pi, 0.005) # 以0.005弧度间隔生成角度
x_ellipse = xc + a * np.cos(angles) * np.cos(np.radians(theta)) - b * np.sin(angles) * np.sin(np.radians(theta))
y_ellipse = yc + a * np.cos(angles) * np.sin(np.radians(theta)) + b * np.sin(angles) * np.cos(np.radians(theta))
# 输出椭圆上的点的坐标
ellipse_points = np.column_stack((x_ellipse, y_ellipse))
print("Ellipse Points:")
print(ellipse_points)
np.savetxt('ellipse_1d.txt', ellipse_points, fmt='%.6f', delimiter='\t', header='X\tY', comments='')
# 绘制拟合的散点及椭圆曲线
plt.figure(figsize=(8, 6))
plt.scatter(data[:, 0], data[:, 1], color='blue', label='Data')
plt.plot(x_ellipse, y_ellipse, color='red', label='Ellipse')
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('Fitted Ellipse')
plt.legend()
plt.axis('equal')
plt.grid(True)
plt.savefig('fitted_ellipse.png') # 保存图形到文件
plt.show()