【问题标题】:Python Simulate Y^2 + Z^2 = (SinX)^2Python 模拟 Y^2 + Z^2 = (SinX)^2
【发布时间】: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


【解决方案1】:

这是一个 VPython 程序,它可以在 3D 中绘制一个函数,这可能与你想做的事情有关。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    • 2020-06-05
    • 2015-04-26
    • 2018-06-14
    相关资源
    最近更新 更多