您的位置:首页 > 编程语言 > PHP开发

用matplotlib画线

2018-03-31 08:58 309 查看
就拿sin、cossin、cos来举例吧。

python代码:

import matplotlib.pyplot as plt
import numpy
import math

#创建x数组,区间是[0,4π],步长为0.1
x = numpy.arange(0, 4 * math.pi, 0.1)

def sinFunction(x):
sin = [math.sin(i) for i in x]
return sin

def cosFunction(x):
cos = [math.cos(i) for i in x]
return cos

plt.plot(x, sinFunction(x), label='sin')
plt.plot(x, cosFunction(x), label='cos')
plt.legend()
plt.show()


图像:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  matplotlib 曲线 sin cos