Contour plot on the surface of a 3D cylinder

2019-03-04 02:37发布

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.

0条回答
登录 后发表回答