【发布时间】:2014-12-04 19:11:11
【问题描述】:
我遇到了一个与绘制椭圆体有关的问题。
我要绘制的椭圆体如下:
x**2/16 + y**2/16 + z**2/16 = 1.
所以我看到了很多与计算和绘制椭圆空隙有关的参考资料,并且在多个问题中提到了笛卡尔到球形或反之亦然的计算。
访问了一个有计算器的网站,但我不知道如何成功执行此计算。此外,我不确定 linspaces 应该设置为什么。已经看到了我在那里的默认库,但由于我以前没有使用这些库的经验,我真的不知道会从中得到什么。
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=plt.figaspect(1)) # Square figure
ax = fig.add_subplot(111, projection='3d')
multip = (1, 1, 1)
# Radii corresponding to the coefficients:
rx, ry, rz = 1/np.sqrt(multip)
# Spherical Angles
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
# Cartesian coordinates
#Lots of uncertainty.
#x =
#y =
#z =
# Plot:
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')
# Axis modifications
max_radius = max(rx, ry, rz)
for axis in 'xyz':
getattr(ax, 'set_{}lim'.format(axis))((-max_radius, max_radius))
plt.show()
【问题讨论】:
标签: python math matplotlib coordinate-systems