用python怎样画出如题所示的正余弦函数图像? 如此编写代码,使其中两个轴、图例、刻度,大小,LaTex公式等要素与原图一致,需要用到的代码如下,没有缩进:
from matplotlib import pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(a,b,label=r"$y=\sin(\theta)$")
ax.plot(a,c,label=r"$y=\cos(\theta)$")
ax.grid(True)
ax.set_ylabel(r"$y$")
ax.set_xlabel(r"$\theta$")
plt.title("Sine Cosine Waves")
plt.legend()
plt.savefig("SinCosWaveDegFont.jpg")
plt.show()
代码运行show的窗口图
代码的截图
代码输出的文件的图
def func_sin():
# 准备 y 轴的数据
y = []
for i in x:
?print(i)
?y.append(math.sin(i))?
# 绘制线图
plt.plot(x, y,c='r' )
# 添加标题
plt.title("y = sin(x)")
# 添加 x 轴的信息
plt.xlabel("x")
# 添加 y 轴的信息
plt.ylabel("y")
# 显示线图
这些函数的单位是弧度,不是角度.
余弦也是cos..
如果仅仅是入门级或轻量级的计算用Math.cos就可以了,numpy显得很重型
以上就是土嘎嘎小编为大家整理的python余弦函数相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!