324 KiB
324 KiB
In [2]:
import pandas as pd
data = pd.read_csv("analysis\\20260128experiment_result.csv")
data = data[["n_max_trial","cap_limit_level","mean_end_ts"]]
dataOut [2]:
| n_max_trial | cap_limit_level | mean_end_ts | |
|---|---|---|---|
| 0 | 7 | 5.0 | 1.8726 |
| 1 | 7 | 10.0 | 2.2829 |
| 2 | 7 | 15.0 | 2.5124 |
| 3 | 5 | 5.0 | 1.8726 |
| 4 | 5 | 10.0 | 2.2840 |
| 5 | 5 | 15.0 | 2.5189 |
| 6 | 3 | 5.0 | 1.8754 |
| 7 | 3 | 10.0 | 2.3349 |
| 8 | 3 | 15.0 | 2.5918 |
In [8]:
import matplotlib.pyplot as plt
# 设置中文字体为宋体
plt.rcParams['font.sans-serif'] = ['SimSun'] # 宋体
plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题
# 1. 画交互作用图
plt.figure(figsize=(4, 3.5), dpi=300)
# 为每个 n_max_trial 水平画一条线
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
for i, n_trial in enumerate(sorted(data['n_max_trial'].unique())):
subset = data[data['n_max_trial'] == n_trial].sort_values('cap_limit_level')
plt.plot(
subset['cap_limit_level'],
subset['mean_end_ts'],
marker='o',
linewidth=2,
markersize=6,
alpha=0.85,
color=colors[i % len(colors)], # <- key line
label=f'{int(n_trial)}'
)
plt.xlabel("额外产能分布均值P6", fontsize=11)
plt.ylabel("产业链供应链恢复时间", fontsize=11)
# plt.title("交互作用图(系统恢复用时R1)\n数据均值", fontsize=12)
plt.legend(title='最大尝试次数P3', loc='upper left')
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()
In [10]:
import seaborn as sns
import matplotlib.pyplot as plt
# 设置中文字体为宋体
plt.rcParams['font.sans-serif'] = ['SimSun'] # 宋体
plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题
# 2. 透视成二维网格
pivot = data.pivot(index="n_max_trial",
columns="cap_limit_level",
values="mean_end_ts")
# 3. 画热力图
plt.figure(figsize=(4, 3), dpi=300) # 正方形,提高分辨率
sns.heatmap(
pivot,
annot=True,
fmt=".3f",
cmap="Blues", # 使用蓝色配色方案
# square=True # 确保每个单元格也是正方形
)
plt.xlabel("额外产能分布均值P6")
plt.ylabel("最大尝试次数P3")
# plt.title("产业链供应链恢复时间")
plt.tight_layout()
plt.show()
In [7]:
from mpl_toolkits.mplot3d import Axes3D
# 网格
Y = data["cap_limit_level"].values.reshape(3,3)
X = data["n_max_trial"].values.reshape(3,3)
Z = data["mean_end_ts"].values.reshape(3,3)
# 画图
fig = plt.figure(figsize=(6,4))
ax = fig.add_subplot(111, projection="3d")
ax.plot_surface(X, Y, Z)
ax.set_xlabel("cap_limit_level")
ax.set_ylabel("n_max_trial")
ax.set_zlabel("mean_end_ts")
ax.set_title("Response Surface")
plt.tight_layout()
plt.show()In [ ]: