如何用python的math函数库和total函数库做sin函数图像
时间: 2023-05-20 15:06:56 浏览: 67
你可以使用以下代码来绘制sin函数图像:
```python
import math
import matplotlib.pyplot as plt
x = [i for i in range(-360, 360)]
y = [math.sin(math.radians(i)) for i in x]
plt.plot(x, y)
plt.show()
```
这段代码使用了Python的math函数库来计算sin函数的值,并使用了matplotlib库来绘制图像。其中,x轴的取值范围为-360到360度,y轴的取值为对应角度的sin值。最后,使用plt.plot函数来绘制图像,并使用plt.show函数来显示图像。
相关问题
如何用python的math函数库和turtle函数库做sin函数图像
可以使用以下代码:
```python
import math
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔速度
turtle.speed(0)
# 设置坐标系
turtle.penup()
turtle.goto(-400, 0)
turtle.pendown()
turtle.goto(400, 0)
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.goto(0, 200)
# 绘制sin函数图像
for x in range(-360, 360):
y = math.sin(math.radians(x))
turtle.goto(x, y * 100)
# 隐藏画笔
turtle.hideturtle()
# 显示图像
turtle.done()
```
这段代码会绘制出一个sin函数的图像。其中,math库中的sin函数用于计算sin值,turtle库用于绘制图像。
pythonmath函数库
Python中的math函数库是一个提供数学运算函数的标准库。可以通过import math语句来导入这个函数库,并使用其中的函数。使用math函数库中的函数时,可以直接采用函数名()的形式进行调用。这个库提供了很多数学运算相关的函数,比如求平方根、对数运算、三角函数等。如果想要使用这个函数库中的函数,需要在代码中导入该库,然后通过库名.函数名()的方式来调用相应的函数。