(results, file_name="rho_vs_acc.png", dir_path=str)
| 440 | print(f"Legend saved to: {legend_path}") |
| 441 | |
| 442 | def plot_sr(results, file_name="rho_vs_acc.png", dir_path=str): |
| 443 | # 输出目录 |
| 444 | # dir_path = r"E:\weichy\ODECode\src\output\Plot\ode" |
| 445 | os.makedirs(dir_path, exist_ok=True) |
| 446 | |
| 447 | # 将 results 解包为三个列表 |
| 448 | spectral_radii, train_accs, test_accs = zip(*results) |
| 449 | |
| 450 | # 绘图 |
| 451 | plt.figure() |
| 452 | plt.plot(spectral_radii, train_accs, marker='o', label='Train Accuracy') |
| 453 | plt.plot(spectral_radii, test_accs, marker='s', label='Test Accuracy') |
| 454 | plt.xlabel("spectral_radius") |
| 455 | plt.ylabel("accuracy") |
| 456 | plt.title("Spectral Radius vs Accuracy") |
| 457 | plt.legend() # 添加图例 |
| 458 | plt.tight_layout() |
| 459 | |
| 460 | # 保存并关闭 |
| 461 | file_path = os.path.join(dir_path, file_name) |
| 462 | plt.savefig(file_path, dpi=300) |
| 463 | plt.close() |
| 464 | |
| 465 | |
| 466 |
nothing calls this directly
no outgoing calls
no test coverage detected