import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # 定义不规则图形的顶点坐标 polygon1_points = np.array([[10, 10], [20, 10], [30, 30], [10, 30]]) polygon2_points = np.array([[40, 40], [60, 40], [60, 60], [40, 60]]) polygon3_points = np.array([[70, 70], [90, 70], [90, 90], [70, 90]]) polygon4_points = np.array([[20, 70], [50, 70], [50, 50], [20, 50]]) # 创建三维图形 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # 定义填充颜色 colors = ['r', 'g','b','y'] # 定义函数来绘制填充图形 def plot_fill_polygon(ax, points, color): x, y = points[:, 0], points[:, 1] X, Y = np.meshgrid(x, y) Z = np.zeros_like(X) ax.plot_surface(X, Y, Z, color=color, alpha=0.5) # ax.contour(X, Y, Z, color=color, alpha=0.5) # 绘制填充图形 plot_fill_polygon(ax, polygon1_points, colors[0]) plot_fill_polygon(ax, polygon2_points, colors[1]) plot_fill_polygon(ax, polygon3_points, colors[2]) plot_fill_polygon(ax, polygon4_points, colors[3]) # 设置坐标轴标签 ax.set_xlabel('X axis') ax.set_ylabel('Y axis') ax.set_zlabel('Z axis') plt.show()