import numpy as np
import matplotlib.pyplot as plt
# 定义要绘制的三角函数类型和参数
trig_func = 'sin' # 三角函数类型,可选值为 'sin'、'cos'、'tan'
start = 0 # 起始值
stop = 2 * np.pi # 结束值
num_points = 1000 # 曲线上的点数
# 生成指定范围内的均匀间隔的点作为x值
x = np.linspace(start, stop, num_points)
# 根据三角函数类型计算y值
if trig_func == 'sin':
y = np.sin(x)
elif trig_func == 'cos':
y = np.cos(x)
elif trig_func == 'tan':
y = np.tan(x)
else:
raise ValueError('Invalid trigonometric function type.')
# 绘制曲线
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel(trig_func)
plt.title(f'{trig_func} Curve')
plt.grid(True)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
# 生成 x 坐标轴上的点
x = np.linspace(-np.pi, np.pi, 100)
# 计算正弦函数的值 【sin可以改为cos、tan】
y = np.sin(x)
# 绘制曲线
plt.plot(x, y)
# 显示图形
plt.show()