《高等数学》同济大学出版:三角函数
编写 test_sin_cos.py 如下
# -*- coding: utf-8 -*-
""" 正弦函数 y=sin(x) 和 余弦函数 y=cos(x) 的曲线 """
import numpy as np
from matplotlib import pyplot as plt
# 用于正常显示中文标题,负号
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x = np.arange(-7.0, 7.01, 0.01)
y = np.sin(x)
y1 = np.cos(x)
print(len(x))
print('sin(x):', y[0], y[-1])
print('cos(x):', y1[0],y1[-1])
# 可视化
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot(x, y, label='sin(x)') # 画曲线
axes.plot(x, y1, label='cos(x)')
#axes.axis('scaled') # 用缩尺制图
axes.axis('equal')
plt.title('正弦函数 y=sin(x) 和 余弦函数 y=cos(x) 的曲线')
plt.xlabel('x')
plt.ylabel('y')
plt.xticks(range(-7,8,1), range(-7,8,1))
plt.yticks(range(-2,3,1), range(-2,3,1))
plt.legend()
plt.grid()
plt.show()
运行 python test_s

最低0.47元/天 解锁文章
2521

被折叠的 条评论
为什么被折叠?



