import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import Normalize
from scipy.interpolate import griddata
# --------------------- 1. 原始数据与公共参数 ---------------------
data = {
"30min": {
"temperatures": [
[0.00, 74.80, 80.08, 80.96, 78.32, 76.56, 0.00],
[0.00, 64.33, 68.87, 69.63, 67.36, 65.84, 0.00],
[0.00, 48.62, 52.05, 52.62, 50.91, 49.76, 0.00],
[0.00, 28.42, 30.43, 30.76, 29.76, 29.09, 0.00],
[0.00, 8.98, 9.61, 9.72, 9.40, 9.19, 0.00],
[0.00, 1.50, 1.60, 1.62, 1.57, 1.53, 0.00]
]
}
}
# 公共参数
depths = [0, 17, 34, 51, 68, 85] # 原始深度 (mm)
horizontal_positions = [0, 50, 150, 250, 350, 450, 500] # 水平位置 (mm)
heating_times = [10, 20, 30] # 加热时间 (min)
profile_idx = horizontal_positions.index(250) # 250mm对应的列索引
mirror_depths = np.concatenate([-np.array(depths[1:])[::-1], depths]) # 镜像深度(对称于0mm)
# --------------------- 2. 绘制2D镜像温度分布图 ---------------------
def plot_2d_mirror():
fig_2d = plt.figure(figsize=(18, 12))
norm = Normalize(vmin=0, vmax=100) # 统一色标0-100℃
cmap = 'jet'
for i, (time_key, time_data) in enumerate(data.items()):
# 创建镜像温度矩阵
original_temps = np.array(time_data["temperatures"])
mirror_temps = np.vstack([original_temps[1:][::-1], original_temps])
# 创建网格
X, Y = np.meshgrid(horizontal_positions, mirror_depths)
# 绘制二维温度分布图
ax = fig_2d.add_subplot(2, 3, i+1)
contour = ax.contourf(X, Y, mirror_temps, levels=20, cmap=cmap, norm=norm)
# 设置标题和坐标轴
ax.set_title(f'Heating Time: {time_key}', fontsize=14)
ax.set_xlabel('Horizontal Position (mm)', fontsize=12)
ax.set_ylabel('Depth (mm)', fontsize=12)
ax.set_xlim(0, 500)
ax.set_ylim(-85, 85)
ax.grid(True, linestyle='--', alpha=0.5)
# 添加色标
cbar = plt.colorbar(contour, ax=ax)
cbar.set_label('Temperature (°C)', fontsize=12)
# 添加250mm处的垂直线
ax.axvline(x=250, color='red', linestyle='--', linewidth=1.5, alpha=0.7)
ax.text(255, 70, '250mm', color='red', fontsize=10,
bbox=dict(facecolor='white', alpha=0.7))
# 添加对称轴标记
ax.axhline(y=0, color='black', linestyle='-', linewidth=1.0)
ax.text(10, 5, 'Symmetry Plane (Depth=0)', color='black', fontsize=10,
bbox=dict(facecolor='white', alpha=0.7))
fig_2d.suptitle('2D Temperature Distribution with Mirror Effect', fontsize=16, y=0.95)
plt.tight_layout(rect=[0, 0, 1, 0.95])
return fig_2d
fig_2d = plot_2d_mirror()
plt.show()
将这个代码所绘制出来的二维平面数据沿Y=0这个轴旋转圈,就得到了维数据,再将>0的区域显示出来。就得到了被加热区域的范围示意图。图形的照片类似一个球形,在我给的代码上扩充完成
最新发布