因为你的帮助很大 https://stackoverflow.com/questions/47333811/how-do-i-create-a-surface-plot-with-matplotlib-of-a-closed-loop-revolve-about-an我现在可以绘制一个内部有孔的 3D 圆柱体:)
这是我的代码:
import numpy as np
import matplotlib as mlp
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d
inner_radius = 100
outer_radius = 300
height=50
# input xy coordinates
input_xy = np.array([[ri,0],[ra,0],[ra,h],[ri,h],[ri,0]])
# radial component is x values of input
r = xy[:,0]
# angular component is one revolution of 30 steps
phi = np.linspace(0, 2*np.pi, 30)
# create grid
R,Phi = np.meshgrid(r,phi)
# transform to cartesian coordinates
X = R*np.cos(Phi)
Y = R*np.sin(Phi)
# Z values are y values, repeated 30 times
Z = np.tile(xy[:,1],len(Y)).reshape(Y.shape)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
#ax2 = fig.add_axes([0.05,0.7,0.15,.2])
#ax2.plot(xy[:,0],xy[:,1], color="k")
ax.set_zlim(0,200)
ax.plot_surface(X, Y, Z, alpha=0.5, color='lightgrey', rstride=1, cstride=1)
plt.show()
对我来说,下一个非常重要的步骤是在顶面上(或者如果可能的话,在 3D 中)绘制一个计数图。它应该看起来像这样(也可以是二维的):等高线图 https://i.stack.imgur.com/UBhF2.jpg
应用于我的情节,它看起来会像这样:我的示例代码上的等高线图 https://i.stack.imgur.com/qBCRc.png
我发现了一些与我的问题类似的东西如何在曲面图上绘制等高线 https://stackoverflow.com/questions/49399748/how-to-plot-contour-lines-on-a-surface-plot-4d/51306259?noredirect=1#comment89590056_51306259但不幸的是我不明白代码。
此致 !
更新:这是我想象的草稿:Target https://i.stack.imgur.com/V23JB.png
我希望有人知道如何处理这个问题。