使用matplotlib库生成图像的三维频谱代码:
时间: 2024-05-08 16:19:19 浏览: 61
以下是使用matplotlib库生成图像的三维频谱代码:
```python
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')
# Generate X, Y, Z coordinates for frequencies
fmax = 10
n = 100
X, Y = np.meshgrid(np.linspace(-fmax, fmax, n), np.linspace(-fmax, fmax, n))
Z = np.sqrt(X**2 + Y**2)
# Generate colormap and plot surface
surf = ax.plot_surface(X, Y, Z, cmap='magma', linewidth=0, antialiased=False)
ax.set_xlabel('Frequency X')
ax.set_ylabel('Frequency Y')
ax.set_zlabel('Amplitude')
ax.set_title('3D Frequency Spectrum')
# Add colorbar
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
```
希望这可以帮到您!
阅读全文