Contour plot on the surface of a 3D cylinder

痴心易碎 提交于 2019-12-20 05:53:30

问题


Because of your great help I can now plot a 3D cylinder with a hole inside :) This is my code:

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()

The next very important step for me would be to plot on the top surface (or maybe in 3d if it is possible) a countor plot. It should look like this (it also can be just in 2d): Contour Plot

Applied to my plot it would look somehow like this:Contour plot on my example code

I found something which looks similar to my problem How to plot contour lines on a surface plot but unfortunately I don't understand the code. Best regards !

Update: Here is a draft of how I imagine it should look like:Target

I hope somebody knows how to handle this problem.

来源:https://stackoverflow.com/questions/51188648/contour-plot-on-the-surface-of-a-3d-cylinder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!