1. 效果

2. 代码
import matplotlib.pyplot as plt
import numpy as np
def hua_qiu(x, y, z, r, dense):
"""
圆心坐标 半径 稠密程度
"""
t = np.linspace(0, np.pi * 2, dense)
s = np.linspace(0, np.pi, dense)
t, s = np.meshgrid(t, s)
x = x + r * np.sin(s) * np.cos(t)
y = y + r * np.sin(s) * np.sin(t)
z = z + r * np.cos(s)
return x, y, z
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xx, yy, zz = hua_qiu(x=0, y=0, z=0, r=1, dense=10)
ax.plot_surface(xx, yy, zz, rstride=1, cstride=1, cmap='gray', alpha=0.5)
plt.show()
3.参考链接
- https://blog.csdn.net/weixin_43794311/article/details/108977841 python-matplotlib显示3D图,球、漏洞、锥体
- https://my.oschina.net/ahaoboy/blog/1836634 matplotlib 绘制三维点阵球
- https://blog.csdn.net/qq_30934313/article/details/85249831 关于matplotlib及相关cmap参数的取值