📜  使用 Matplotlib 的 3D 正弦波 – Python

📅  最后修改于: 2022-05-13 01:54:57.880000             🧑  作者: Mango

使用 Matplotlib 的 3D 正弦波 – Python

先决条件: Mathplotlib、NumPy

在笛卡尔坐标系中,三角正弦函数sin(x) sin (x) 生成一条规则的起伏曲线,该曲线通过原点。对于 x x 的所有实数值,它的值范围在 −1 − 1 和 1 1 之间。
在本文中,我们将使用 3 维散点图绘制正弦波图。使用 matplotlib 在Python中绘制正弦波的简单方法。

方法:

  • 导入所需的库。
  • 创建一个点数组。
  • 绘制 3D 图形。
  • 创造一个罪恶波。
  • 显示图表。

示例 1:在本示例中,我们使用散射法绘制正弦波信号的 3 维图。

Python3
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
  
# Creating array points using numpy
x = np.arange(0, 20, 0.1)
y = np.sin(x)
z = y*np.sin(x)
c = x + y
  
#Change the Size of Graph using Figsize
fig = plt.figure(figsize = (10, 10))
  
#Generating a 3D sine wave
ax = plt.axes(projection = '3d')
  
# To create a scatter graph
ax.scatter(x, y, z, c = c)
  
# show the graph 
plt.show()


Python3
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
  
fig = plt.figure(figsize=(8, 8))
ax = plt.axes(projection = '3d')
  
# Creating array points using numpy
z = np.linspace(0, 15, 1000)
x = np.sin(zline)
y = np.cos(zline)
ax.plot3D(x, y, z, 'gray')
  
plt.show()


输出:

示例 2:在本示例中,我们绘制了一个简单的正弦波信号的 3-D 折线图。

蟒蛇3

from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
  
fig = plt.figure(figsize=(8, 8))
ax = plt.axes(projection = '3d')
  
# Creating array points using numpy
z = np.linspace(0, 15, 1000)
x = np.sin(zline)
y = np.cos(zline)
ax.plot3D(x, y, z, 'gray')
  
plt.show()

输出: