0

I use matplotlib to simulate Y^2 + Z^2 = (SinX)^2

That is,the sine graph rotate 360 degrees based on x axis.

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()

Following is the image

However,that seems not fit my expectation.

Is my way reasonable?

Or is there any way can implement in vpython?

Jonathan Cheng
  • 459
  • 2
  • 11
  • 26
  • The equation you list at the top of the question doesn't match either what you describe or what your code does. I'd expect it to be a 3D surface (not a single line), resembling a chain of sausage links running along the x-axis. Note that `Y**2 + Z**2 = c**2` for some constant `c` is the equation of a circle. – Blckknght Nov 07 '17 at 19:01
  • I have updated my code with the surface.If I want to make a sausage link,which part should I fixed? – Jonathan Cheng Nov 07 '17 at 20:11
  • Sorry, I don't know much at all about plotting in Python, I just recognized the equation. It might help if you could figure out how to plot a cylinder around one axis. – Blckknght Nov 07 '17 at 20:32

1 Answers1

0

Here is a VPython program that plots a function in 3D, which may be related to what you want to do.

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

user1114907
  • 972
  • 8
  • 15