| import numpy as np |
| import matplotlib |
| import matplotlib.pyplot as plt |
| from mpl_toolkits.mplot3d import Axes3D |
|
|
| |
| matplotlib.use("Agg") |
|
|
| |
| x_values = np.array([1, 3, 5, 7, 9]) |
| y_values = np.array([0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5, 1.7, 1.9, 2.1, 2.3, 2.5, 2.7, 2.9]) |
|
|
| |
| X, Y = np.meshgrid(x_values, y_values) |
|
|
| |
| |
| |
| |
|
|
| |
| Z = np.array([ |
| [11.9, 14.8, 13.7, 13.0, 10.8], |
| [17.5, 10.8, 10.3, 14.3, 13.0], |
| [29.2, 31.7, 13.5, 10.1, 14.8], |
| [20.0, 30.8, 23.3, 14.2, 11.1], |
| [10.9, 23.3, 25.0, 24.2, 10.9], |
| [23.3, 24.2, 23.3, 29.2, 21.7], |
| [21.7, 27.5, 22.5, 25.8, 25.0], |
| [11.5, 23.3, 17.5, 26.7, 27.5], |
| [24.2, 24.2, 16.7, 23.3, 29.2], |
| [18.3, 24.2, 27.5, 20.0, 25.8], |
| [25.8, 25.8, 26.7, 21.7, 28.3], |
| [28.3, 26.2, 23.3, 20.8, 26.7], |
| [20.0, 24.2, 20.0, 20.0, 28.3], |
| [23.3, 26.2, 21.7, 24.2, 24.2], |
| [15.8, 22.5, 20.8, 25.8, 23.3], |
| ]) |
|
|
| |
| fig = plt.figure(figsize=(12, 8)) |
| ax = fig.add_subplot(111, projection='3d') |
|
|
| |
| surf = ax.plot_surface(X, Y, Z, cmap='RdYlBu_r', alpha=0.8, edgecolor='none') |
|
|
| |
| ax.set_xlabel('Init Value', fontsize=12, labelpad=10) |
| ax.set_ylabel('Temperature', fontsize=12, labelpad=10) |
| ax.set_zlabel('Performance', fontsize=12, labelpad=10) |
|
|
| |
| ax.set_title('Performance vs Init Value and Temperature', fontsize=18, pad=10) |
|
|
| |
| colorbar = fig.colorbar(surf, ax=ax, shrink=0.5, aspect=10, pad=0.05) |
| colorbar.set_label('Performance', rotation=270, labelpad=15) |
|
|
| |
| ax.view_init(elev=30, azim=45) |
|
|
| |
| ax.set_xticks(x_values) |
| ax.set_yticks(y_values) |
| |
| |
|
|
| |
| ax.grid(False) |
|
|
| |
| ax.xaxis.pane.fill = False |
| ax.yaxis.pane.fill = False |
| ax.zaxis.pane.fill = False |
| ax.xaxis.pane.set_edgecolor('none') |
| ax.yaxis.pane.set_edgecolor('none') |
| ax.zaxis.pane.set_edgecolor('none') |
|
|
| |
| plt.tight_layout() |
| plt.savefig('3d_surface_plot.png', dpi=300, bbox_inches='tight', transparent=True) |
| plt.close() |
|
|
| print("3D表面图已保存为: 3d_surface_plot.png") |
|
|
| |
| plt.figure(figsize=(7, 5)) |
|
|
| num_levels = 15 |
| |
| contourf = plt.contourf(X, Y, Z, levels=num_levels, cmap='RdYlBu_r', alpha=0.7) |
|
|
| |
| contour_lines = plt.contour(X, Y, Z, levels=num_levels, colors='black', alpha=0.5, linewidths=1.5) |
|
|
| |
| cbar = plt.colorbar(contourf, shrink=0.8, aspect=15, pad=0.02) |
| cbar.set_label("Performance", rotation=270, labelpad=15) |
|
|
| |
| plt.xlabel('Init Value', fontsize=12) |
| plt.ylabel('Temperature', fontsize=12) |
|
|
| |
| plt.title('Performance Contour Plot', fontsize=18, pad=10) |
|
|
| |
| plt.grid(False) |
|
|
| |
| plt.xticks(x_values) |
| plt.yticks(y_values) |
|
|
| |
| plt.tight_layout() |
| plt.savefig('contour_plot.png', dpi=300, bbox_inches='tight', transparent=True) |
| plt.close() |
|
|
| print("等高线图已保存为: contour_plot.png") |
| print("所有图片已成功保存!") |