Python 繪製三角函數圖形

Ping-Lun Liao
1 min readFeb 7, 2019

--

問題:「如何使用Python來繪製三角函數圖形呢?」
OK,在繪製圖形前,先來了解 Python 的數學程式庫(Mathematical functions)有哪些,從3.6.2的文件可看到如下:

在Trigonometric functions一節中可查到底下三個:

math.cos(x)

Return the cosine of x radians.

math.sin(x)

Return the sine of x radians.

math.tan(x)

Return the tangent of x radians.

所以可以用這三個數學函數來繪製。但是Python有比上面函式還好用的程式庫,叫做NumPy。使用NumPy可以快速產生繪圖資料。接下來要處理繪圖的功能,在 Python 的程式庫中,有Matplotlib可用,就用此程式庫來繪圖囉。

範例程式:

輸出圖:

Originally published at yunlinsong.blogspot.com on February 7, 2019.

--

--

No responses yet