Python模拟Y ^ 2 + Z ^ 2 =(SinX)^ 2

时间:2017-11-07 18:35:06

标签: python matplotlib vpython

我使用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中实现?

1 个答案:

答案 0 :(得分:0)

这是一个VPython程序,用于绘制3D中的函数,这可能与您想要做的事情有关。

http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Plot3D