我已经在matplotlib中使用plot_surface(X,Y,Z)绘制了3D表面。我有绘制在每个表面上的结果。如何在代码中给出的3D几何的每个表面上绘制等高线图。
有人可以通过在X1,Y1,Z1平面上绘制Z值来帮助我。
from matplotlib import pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib notebook
length_of_str = 30
width_of_str = 18
height_of_str = 16
mesh = [2, 2, 2]
x = np.arange(0,length_of_str+1,mesh[0])
y = np.arange(0,width_of_str+1,mesh[1])
z = np.arange(0,height_of_str+1,mesh[2])
X1, Y1 = np.meshgrid(x, y)
Z1 = np.zeros((len(y), len(x)))
Z1.fill(height_of_str)
R = np.sqrt(X1**2 + Y1**2)
Z = np.sin(R)
X2, Z2 = np.meshgrid(x, z)
Y2 = np.zeros((len(z), len(x)))
X3, Z3 = np.meshgrid(x, z)
Y3 = np.zeros((len(z), len(x)))
Y3.fill(width_of_str)
Y4, Z4 = np.meshgrid(y, z)
X4 = np.zeros((len(z), len(y)))
Y5, Z5 = np.meshgrid(y, z)
X5 = np.zeros((len(z), len(y)))
X5.fill(length_of_str)
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.plot_surface(X1, Y1, Z1)
ax.plot_surface(X2, Y2, Z2)
ax.plot_surface(X3, Y3, Z3)
ax.plot_surface(X4, Y4, Z4)
ax.plot_surface(X5, Y5, Z5)
ax.set_xlim(0,max(length_of_str,width_of_str,height_of_str))
ax.set_ylim(0,max(length_of_str,width_of_str,height_of_str))
ax.set_zlim(0,max(length_of_str,width_of_str,height_of_str))
plt.show()