【发布时间】:2017-11-07 18:35:05
【问题描述】:
我用matplotlib模拟Y^2 + Z^2 = (SinX)^2
即正弦图以x轴为基准旋转360度。
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
# Make data.
t = np.arange(-5, 5, 0.25)
X,Y = np.meshgrid(t,t)
Z = np.sin(t)**2
# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
# Customize the z axis.
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
下面是image
但是,这似乎不符合我的期望。
我的方式合理吗?
或者有什么方法可以在 vpython 中实现?
【问题讨论】:
-
您在问题顶部列出的方程式与您所描述的或您的代码所做的不匹配。我希望它是一个 3D 表面(不是一条线),类似于沿 x 轴运行的一串香肠链接。请注意,
Y**2 + Z**2 = c**2对于某些常数c是一个圆的方程。 -
我已经用表面更新了我的代码。如果我想做一个香肠链接,我应该修复哪个部分?
-
抱歉,我对 Python 中的绘图一无所知,我只是认出了方程式。如果您能弄清楚如何围绕一个轴绘制圆柱体,这可能会有所帮助。
标签: python matplotlib vpython