Python绘制圆柱体

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 创建一个3D坐标轴
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# 圆柱体的高度和半径
height = 5
radius = 1

# 创建圆柱体的表面网格
theta = np.linspace(0, 2. * np.pi, 50)
z = np.linspace(0, height, 50)
theta_grid, z_grid = np.meshgrid(theta, z)
x_grid = radius * np.cos(theta_grid)
y_grid = radius * np.sin(theta_grid)

# 绘制圆柱体的侧面
ax.plot_surface(x_grid, y_grid, z_grid, color='b', alpha=0.8)

# 绘制圆柱体的顶部和底部
ax.plot_surface(x_grid, y_grid, np.full_like(z_grid, 0), color='b', alpha=0.5)  # 底部
ax.plot_surface(x_grid, y_grid, np.full_like(z_grid, height), color='b', alpha=0.5)  # 顶部

# 设置坐标轴的范围和标签
ax.set_xlim([-1.5 * radius, 1.5 * radius])
ax.set_ylim([-1.5 * radius, 1.5 * radius])
ax.set_zlim([0, height + 1])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# 显示图形
plt.show()

程序结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MATLAB代码顾问

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值