
正文
用python画三角函数 python绘制三角函数图像
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Python如何画cos和sin的图啊?
在python自带编辑器IDLE中,新建脚本如作图.py
导入需要的模块
import numpy as np
import scipy as sp
import pylab as pl
2
输入代码
x=np.linspace(0,4*np.pi,100)
pl.plot(x,pl.sin(x))
pl.show()
3
执行代码,按F5,可直接显示图片
4
几点说明:
1. 方法linspace(0,4*np.pi,100)表示从0开始,到4*pi结束,生成100个点
2. 方法plot为画图函数,相当于plot(x,y),x为横坐标,y为纵坐标
3.show()为展示出来
希望采纳!!
相关问答
Q1: 如何在python中表达三角函数,比如sin(x),tan(x),谢谢
在python中,有一个math
module,你可以import
math,
里面有math.sin(),math.cos(),math.asin()和math.acos()四个函数.
有了这四个函数你就可以求函数值和角度了.
注意:括号里面填的数值,要用弧度制.
Q2: 如何用python表示三角函数
在python中,有一个math module,你可以import math,里面有math.sin(), math.cos(), math.asin()和math.acos()四个函数。相信你也知道asin和acos的意思,就是arcsin和arccos。有了这四个函数你就可以求函数值和角度了。但是要注意括号里面填的数值,要用弧度制。
Q3: 简单python语言编程:采用自顶向下设计方法编写程序:在屏幕上打印三角函数y = sin(x)的图像。
I just wrote an simple one for one other guy.
You may check it here and see if it's useful for you.
Q4: 如何用python完成:用自顶向下设计方法编写程序:在屏幕上打印三角函数y = sin(x)的图像。
I wrote this in Tkinter for you, in case you don't know Tkinter, it is a built-in module for most python versions.
If you want a commandline version, you can ask me, but tell you what, since those values are all
float numbers, so it's hard to get a precise graph in commandline window.
Well, in this version, I enlarged each element's position by 40 and then change them to integer, guess this is an endurable loss of precision.
#
from math import radians
from math import sin
from Tkinter import *
pos = []
xPos = 0
centerX = 0
centerY = 0
for deg in range(-360, 361, 10):
pos.append([xPos, int(40*(sin(radians(deg))))]) #1000 too big for my screen
xPos+=1
if deg == 0:
centerX = xPos-1
centerY = pos[-1][1]
root = Tk()
root.title('trianble graph from -180 to 180')
width, height = 550, 450
mHei = height/2
mWid = width/2
canvas = Canvas(root, width=width, height=height)
canvas.create_line(0, mHei, width, mHei) #x axis
canvas.create_line(mWid, 0, mWid, height) #y axis
xStep = (width-150)/len(pos)
yStep = (height-150)/len(pos)
radius = 3
# the middle point (sin(0) is first drawn and used as position reference for all
canvas.create_oval(mWid-radius, mHei-radius, mWid+radius, mHei+radius, fill='green')
print pos
print xStep, yStep, centerX, centerY
#exit(0)
for i in pos:
if i[0] == centerX: #center processed already.
continue
x = mWid + xStep*(i[0]-centerX)
# y is smaller, the bigger the value, so use minus
y = mHei - yStep*(i[1]-centerY)
canvas.create_oval(x-radius, y-radius, x+radius, y+radius, fill='green')
canvas.pack()
root.mainloop()
Q5: sin15°用Python怎么表示?
Python的三角函数sin(),输入参数必须是弧度,所以要把角度变换为弧度
import math
# .... 输入度数到 degrees 变量....
# 例子里用 30度计算
degrees=30
radians = degrees * math.pi / 180.0
value = round( math.sin(radians), 4)
print(value)
关于用python画三角函数和python绘制三角函数图像的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






