畫出三維表面圖 Z = sin ( x 2 + y 2 ) \text{畫出三維表面圖}Z=\sin \left( \sqrt{x^2+y^2} \right) 畫出三維表面圖Z=sin(x2+y2)
import pylab as plt
import numpy as np
ax=plt.axes(projection="3d")
X=np.arange(-6,6,0.25)
Y=np.arange(-6,6,0.25)
X,Y=np.meshgrid(X,Y)
Z=np.sin(np.sqrt(X**2+Y**2))
surf=ax.plot_surface(X,Y,Z,cmap="coolwarm")
plt.colorbar(surf)
plt.show()
畫出三維曲面圖 Z = 50 sin ( x + y ) \text{畫出三維曲面圖}Z=50\sin \left( x+y \right) 畫出三維曲面圖Z=50sin(x+y)
import pylab as plt
import numpy as np
x=np.linspace(-4,4,100)
x,y=np.meshgrid(x,x)
z=50*np.sin(x+y)
ax=plt.axes(projection="3d")
ax.plot_surface(x,y,z,cmap="coolwarm")
plt.show()
畫出三維曲線 x = s 2 sin s , y = s 2 cos s , s = s , s ∈ [ − 50 , 50 ] \text{畫出三維曲線}x=s^2\sin s,y=s^2\cos s,s=s,s\in \left[ -50,50 \right] 畫出三維曲線x=s2sins,y=s2coss,s=s,s∈[−50,50]
import pylab as plt
import numpy as np
s=np.linspace(-50,50,1000)
x=s**2*np.sin(s);y=s**2*np.cos(s)
ax=plt.axes(projection="3d")
ax.plot(x,y,s,"k")
plt.show()