简体   繁体   English

在python中绘制圆柱体

[英]plot a cylinder in python

I am trying to plot a full cylinder, using a cylindrical mesh grid. 我正在尝试使用圆柱网格网格绘制一个完整的圆柱。 However I just managed to get half a cylinder. 但是我只是设法得到了半个气缸。 Here is my code 这是我的代码

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
r = 1
x = np.linspace(-r, r, 50)
y = np.linspace(-r, r, 50)
X, Y = np.meshgrid(x, y)
Z = (np.pi * -Y**2)
surf = ax.plot_surface(X, Y, Z)

What I would like to obtain is something like this 我想得到的是这样的 在此处输入图片说明

Could anybody give me some insights on how to do it? 有人能给我一些如何做的见解吗?

In this post the ax.plot_surface function is called twice. 本文中 ,ax.plot_surface函数被调用了两次。 In your case adding a minus sign to the Z does not yet result in a cylinder, but at least you have a top and bottom part. 在您的情况下,向Z添加减号尚不能产生圆柱体,但至少您具有顶部和底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM