import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import make_interp_spline
# 设置中文字体
plt.rcParams['font.sans-serif'] = ['WenQuanYi Zen Hei']
plt.rcParams['axes.unicode_minus'] = False
# 创建数据框
data = {
'波形变形/‰': [0, 0.04, 0.08, 0.12, 0.16, 0.2, 0.24, 0.29, 0.33, 0.37, 0.41, 0.45, 0.49, 0.53, 0.57, 0.61, 0.65, 0.69, 0.73, 0.78, 0.82, 0.86, 0.9, 0.94, 0.98, 1.02, 1.06, 1.1, 1.14, 1.18, 1.22, 1.27, 1.31, 1.35, 1.39, 1.43, 1.47, 1.51, 1.55, 1.59, 1.63, 1.67, 1.71, 1.75, 1.8, 1.84, 1.88, 1.92, 1.96, 2],
'FsimC_波形': [1, 1, 0.9905, 0.9901, 0.9897, 0.9893, 0.989, 0.9886, 0.9881, 0.9877, 0.9872, 0.9868, 0.9862, 0.9857, 0.9853, 0.9848, 0.9842, 0.9836, 0.9831, 0.9825, 0.9819, 0.9814, 0.9808, 0.9802, 0.9796, 0.9791, 0.9785, 0.9779, 0.9774, 0.9768, 0.9762, 0.9756, 0.975, 0.9744, 0.9738, 0.9732, 0.9726, 0.972, 0.9714, 0.9708, 0.9702, 0.9696, 0.969, 0.9684, 0.9678, 0.9672, 0.9666, 0.9659, 0.9652, 0.9646],
'弓形变形/‰': [0, 0.06, 0.12, 0.18, 0.24, 0.31, 0.37, 0.43, 0.49, 0.55, 0.61, 0.67, 0.73, 0.8, 0.86, 0.92, 0.98, 1.04, 1.1, 1.16, 1.22, 1.29, 1.35, 1.41, 1.47, 1.53, 1.59, 1.65, 1.71, 1.78, 1.84, 1.9, 1.96, 2.02, 2.08, 2.14, 2.2, 2.27, 2.33, 2.39, 2.45, 2.51, 2.57, 2.63, 2.69, 2.76, 2.82, 2.88, 2.94, 3],
'FsimC_弓形': [1, 1, 0.9774, 0.948, 0.9258, 0.9076, 0.8932, 0.8795, 0.868, 0.8575, 0.8484, 0.84, 0.8329, 0.8266, 0.8204, 0.814, 0.8076, 0.8015, 0.7955, 0.79, 0.7846, 0.7791, 0.7739, 0.7693, 0.7647, 0.7601, 0.7559, 0.7516, 0.7475, 0.7437, 0.7394, 0.7351, 0.7313, 0.7275, 0.7237, 0.7199, 0.7164, 0.7129, 0.71, 0.7068, 0.7037, 0.7009, 0.698, 0.6952, 0.6922, 0.6897, 0.6868, 0.6845, 0.6822, 0.6795],
'组装影响/mm': [0, 0.041, 0.082, 0.122, 0.163, 0.204, 0.245, 0.286, 0.327, 0.367, 0.408, 0.449, 0.49, 0.531, 0.571, 0.612, 0.653, 0.694, 0.735, 0.776, 0.816, 0.857, 0.898, 0.939, 0.98, 1.02, 1.061, 1.102, 1.143, 1.184, 1.224, 1.265, 1.306, 1.347, 1.388, 1.429, 1.469, 1.51, 1.551, 1.592, 1.633, 1.673, 1.714, 1.755, 1.796, 1.837, 1.878, 1.919, 1.959, 2],
'FsimC_组装': [1, 1, 0.9918, 0.9826, 0.9752, 0.9681, 0.9618, 0.9563, 0.951, 0.9456, 0.9403, 0.9351, 0.9304, 0.9261, 0.9222, 0.9192, 0.9166, 0.9128, 0.9088, 0.9063, 0.9041, 0.9015, 0.8989, 0.896, 0.8941, 0.8929, 0.8914, 0.8907, 0.8896, 0.8874, 0.8851, 0.8829, 0.8808, 0.8781, 0.8766, 0.8746, 0.8728, 0.8708, 0.8687, 0.8666, 0.8645, 0.8622, 0.86, 0.8578, 0.8561, 0.8544, 0.8523, 0.8502, 0.8484, 0.8463],
'安装影响/mm': [0, 0.1, 0.2, 0.31, 0.41, 0.51, 0.61, 0.71, 0.82, 0.92, 1.02, 1.12, 1.22, 1.33, 1.43, 1.53, 1.63, 1.73, 1.84, 1.94, 2.04, 2.14, 2.24, 2.35, 2.45, 2.55, 2.65, 2.76, 2.86, 2.96, 3.06, 3.16, 3.27, 3.37, 3.47, 3.57, 3.67, 3.78, 3.88, 3.98, 4.08, 4.18, 4.29, 4.39, 4.49, 4.59, 4.69, 4.8, 4.9, 5],
'FsimC_安装': [1, 1, 0.9982, 0.9969, 0.9953, 0.9936, 0.9917, 0.9896, 0.9872, 0.9836, 0.9809, 0.978, 0.9749, 0.9717, 0.968, 0.9647, 0.9612, 0.9578, 0.9543, 0.9504, 0.947, 0.9436, 0.9401, 0.9368, 0.9331, 0.9298, 0.9263, 0.9232, 0.9199, 0.917, 0.9142, 0.9115, 0.909, 0.9064, 0.9041, 0.9019, 0.8998, 0.8978, 0.8957, 0.8938, 0.8919, 0.8901, 0.8884, 0.8864, 0.8848, 0.8831, 0.8815, 0.8799, 0.8782, 0.8768]
}
df = pd.DataFrame(data)
# 创建2x2子图布局
fig, axes = plt.subplots(2, 2, figsize=(16, 12))
fig.suptitle('不同影响因素对FsimC值的影响', fontsize=20, fontweight='bold', y=0.98)
# 定义颜色和标记
colors = ['#2E86AB', '#A23B72', '#F18F01', '#C73E1D']
markers = ['o', 's', '^', 'D']
line_styles = ['-', '--', '-.', ':']
# 定义插值函数
def create_spline(x, y, num_points=100):
spl = make_interp_spline(x, y, k=3) # 三次样条插值
x_smooth = np.linspace(x.min(), x.max(), num_points)
y_smooth = spl(x_smooth)
return x_smooth, y_smooth
# 1. 波形变形 vs FsimC
ax1 = axes[0, 0]
x1, y1 = df['波形变形/‰'], df['FsimC_波形']
x1_smooth, y1_smooth = create_spline(x1, y1)
ax1.scatter(x1, y1, color=colors[0], marker=markers[0], s=60, alpha=0.8, label='实测数据')
ax1.plot(x1_smooth, y1_smooth, color=colors[0], linestyle=line_styles[0], linewidth=2, label='拟合曲线')
ax1.set_xlabel('波形变形/‰', fontsize=12, fontweight='bold')
ax1.set_ylabel('FsimC值', fontsize=12, fontweight='bold')
ax1.set_title('波形变形对FsimC值的影响', fontsize=14, fontweight='bold', pad=20)
ax1.legend(fontsize=10)
ax1.grid(True, alpha=0.3)
ax1.set_ylim(0.96, 1.005) # 调整y轴范围以突出变化
# 2. 弓形变形 vs FsimC
ax2 = axes[0, 1]
x2, y2 = df['弓形变形/‰'], df['FsimC_弓形']
x2_smooth, y2_smooth = create_spline(x2, y2)
ax2.scatter(x2, y2, color=colors[1], marker=markers[1], s=60, alpha=0.8, label='实测数据')
ax2.plot(x2_smooth, y2_smooth, color=colors[1], linestyle=line_styles[1], linewidth=2, label='拟合曲线')
ax2.set_xlabel('弓形变形/‰', fontsize=12, fontweight='bold')
ax2.set_ylabel('FsimC值', fontsize=12, fontweight='bold')
ax2.set_title('弓形变形对FsimC值的影响', fontsize=14, fontweight='bold', pad=20)
ax2.legend(fontsize=10)
ax2.grid(True, alpha=0.3)
ax2.set_ylim(0.67, 1.005)
# 3. 组装影响 vs FsimC
ax3 = axes[1, 0]
x3, y3 = df['组装影响/mm'], df['FsimC_组装']
x3_smooth, y3_smooth = create_spline(x3, y3)
ax3.scatter(x3, y3, color=colors[2], marker=markers[2], s=60, alpha=0.8, label='实测数据')
ax3.plot(x3_smooth, y3_smooth, color=colors[2], linestyle=line_styles[2], linewidth=2, label='拟合曲线')
ax3.set_xlabel('组装影响/mm', fontsize=12, fontweight='bold')
ax3.set_ylabel('FsimC值', fontsize=12, fontweight='bold')
ax3.set_title('组装影响对FsimC值的影响', fontsize=14, fontweight='bold', pad=20)
ax3.legend(fontsize=10)
ax3.grid(True, alpha=0.3)
ax3.set_ylim(0.84, 1.005)
# 4. 安装影响 vs FsimC
ax4 = axes[1, 1]
x4, y4 = df['安装影响/mm'], df['FsimC_安装']
x4_smooth, y4_smooth = create_spline(x4, y4)
ax4.scatter(x4, y4, color=colors[3], marker=markers[3], s=60, alpha=0.8, label='实测数据')
ax4.plot(x4_smooth, y4_smooth, color=colors[3], linestyle=line_styles[3], linewidth=2, label='拟合曲线')
ax4.set_xlabel('安装影响/mm', fontsize=1
请检查以上python代码,同时修正