怎么用python画圆柱_python – 添加圆柱到绘图

一种可能的方法是使用plot_surface.适应

in this blog post给出的解决方案

import matplotlib.pyplot as plt

import numpy as np

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

# Scatter graph

N = 100

X = np.random.uniform(-1, 1, N)

Y = np.random.uniform(-1, 1, N)

Z = np.random.uniform(-2, 2, N)

ax.scatter(X, Y, Z)

# Cylinder

x=np.linspace(-1, 1, 100)

z=np.linspace(-2, 2, 100)

Xc, Zc=np.meshgrid(x, z)

Yc = np.sqrt(1-Xc**2)

# Draw parameters

rstride = 20

cstride = 10

ax.plot_surface(Xc, Yc, Zc, alpha=0.2, rstride=rstride, cstride=cstride)

ax.plot_surface(Xc, -Yc, Zc, alpha=0.2, rstride=rstride, cstride=cstride)

ax.set_xlabel("X")

ax.set_ylabel("Y")

ax.set_zlabel("Z")

plt.show()

我添加了一些表面的最小配置,更好的是可以通过咨询docs来实现.

你可能感兴趣的:(怎么用python画圆柱)