我生成了一个1D正弦波,然后每行重复一次,以产生2D正弦波。我可以在2d空间中显示它,但是我需要制作一个3D图,显示峰和谷以及它们之间的振荡模式。
import numpy as np
import matplotlib.pyplot as plt
N = 256
x = np.linspace(-np.pi,np.pi, N)
sine1D = 128.0 + (127.0 * np.sin(x))
sine1D = np.uint8(sine1D)
sine2D = np.tile(sine1D, (N,1))
plt.imshow(sine2D, cmap='gray')
答案 0 :(得分:3)
如@Warren Weckesser所说,如何使用mplot3d toolkit examples gallery,例如正弦波大小随时间和相位变化的表面图:
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
fig = plt.figure()
ax3d = fig.add_subplot(111, projection='3d')
# Make the X, Y meshgrid instead of np.tile
xs = np.linspace(-2*np.pi, 2*np.pi, 200)
ys = np.linspace(-2*np.pi, 2*np.pi, 200)
tau, phi = np.meshgrid(xs, ys)
# Z evaluation
amp = np.sin(tau+phi)
ax3d.set_xlabel(r'$\tau$') # tau = omega*t -> adimensional time
ax3d.set_ylabel(r'$\phi$') # phi -> phase
ax3d.set_zlabel(r'$amp$') # signal amplitude
surf = ax3d.plot_surface(tau, phi, amp,cmap=cm.inferno)
fig.colorbar(surf)
给出: