我们如何在 python 3 中绘制旋转体(使用 matplotlib)?
How can we plot solids of revolution in python 3 (with matplotlib)?
我是 Scilab 的用户,但我正在更改为 python(因为我也需要符号分析),现在我是新的 Python 用户,如何绘制旋转实体?
Matplotlib 绘制 3D 网格。有了它,你就可以策划一场革命。你有几个例子 here。一个这样的例子是:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
如果你想要更多direct you might want to try using pycsg, pythonOCC framework or sympy。
最后一个资源有点超出Python。您可以使用 Sage (uses Python syntax) to do Solids of Revolution.
我是 Scilab 的用户,但我正在更改为 python(因为我也需要符号分析),现在我是新的 Python 用户,如何绘制旋转实体?
Matplotlib 绘制 3D 网格。有了它,你就可以策划一场革命。你有几个例子 here。一个这样的例子是:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
如果你想要更多direct you might want to try using pycsg, pythonOCC framework or sympy。
最后一个资源有点超出Python。您可以使用 Sage (uses Python syntax) to do Solids of Revolution.