From 0bfcc53ea8eb97629deac91b5816a9002a84005a Mon Sep 17 00:00:00 2001 From: vincentcxy <55447800+vincentcxy@users.noreply.github.com> Date: Sun, 7 Jul 2024 21:46:18 +0800 Subject: [PATCH] Update Bk3_Ch16_01.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由于 matplotlib 在 3.8.0 版本中 将 contour 的 collections 属性弃用并将 contour 修改为 collections 的子类。因此需要使用 get_path 来获取等高线路径。 --- Book3_Ch16_Python_Codes/Bk3_Ch16_01.py | 52 ++++++++++++-------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/Book3_Ch16_Python_Codes/Bk3_Ch16_01.py b/Book3_Ch16_Python_Codes/Bk3_Ch16_01.py index f187c18..025855a 100644 --- a/Book3_Ch16_Python_Codes/Bk3_Ch16_01.py +++ b/Book3_Ch16_Python_Codes/Bk3_Ch16_01.py @@ -253,34 +253,30 @@ def plot_surface(xx, yy, surface, title_txt): fig.colorbar(colorbar, ax=ax) -for i in range(0,len(CS_y.allsegs[0])): - - contour_points_x_y = CS_y.allsegs[0][i] - - contour_points_z = f_xy_fcn(contour_points_x_y[:,0], - contour_points_x_y[:,1]) - - - ax.plot3D(contour_points_x_y[:,0], - contour_points_x_y[:,1], - contour_points_z, - color = '#339933', - linewidth = 1) - - -for i in range(0,len(CS_x.allsegs[0])): - - contour_points_x_y = CS_x.allsegs[0][i] - - contour_points_z = f_xy_fcn(contour_points_x_y[:,0], - contour_points_x_y[:,1]) - - - ax.plot3D(contour_points_x_y[:,0], - contour_points_x_y[:,1], - contour_points_z, - color = '#00448A', - linewidth = 1) +for path in CS_x.get_paths(): + for subpath in path._iter_connected_components(): + contour_points_x_y = subpath.vertices + contour_points_z = f_xy_fcn(contour_points_x_y[:, 0], + contour_points_x_y[:, 1]) + + ax.plot3D(contour_points_x_y[:, 0], + contour_points_x_y[:, 1], + contour_points_z, + color='#339933', + linewidth=1) + + +for path in CS_y.get_paths(): + for subpath in path._iter_connected_components(): + contour_points_x_y = subpath.vertices + contour_points_z = f_xy_fcn(contour_points_x_y[:, 0], + contour_points_x_y[:, 1]) + + ax.plot3D(contour_points_x_y[:, 0], + contour_points_x_y[:, 1], + contour_points_z, + color='#00448A', + linewidth=1) ax.set_proj_type('ortho')