首页 > 编程知识 正文

python 绘制三角函数Python 绘制三角函数

时间:2023-05-05 22:11:30 阅读:281045 作者:4193

python 绘制三角函数

Trigonometry is one of the most important parts in engineering and many times, therefore matplotlib.pyplot in combination with NumPy can help us to plot our desired trigonometric functions. In this article, we are going to introduce a few examples of trig-functions.

三角学是工程学中最重要的部分之一,因此, matplotlib.pyplot与NumPy结合可以帮助我们绘制所需的三角函数。 在本文中,我们将介绍一些三角函数的例子。

1)正弦函数 (1) Sine Function) s = np.sin(t)fig, ax = plt.subplots()ax.plot(t, s)ax.set(xlabel='radians', ylabel='Sin(x)', title='Sine Plot')ax.grid()plt.show() 2)余弦函数 (2) Cosine Function) s = np.cos(t)fig, ax = plt.subplots()ax.plot(t, s)ax.set(xlabel='radians', ylabel='(cosx)', title='Cosine Plot')ax.grid()plt.show() 3)切线函数 (3) Tangent Function) t = np.arange(0.0, 1, 0.01)s = np.tan(t)fig, ax = plt.subplots()ax.plot(t, s)ax.set(xlabel='radians', ylabel='tan(x)', title='Tangent Plot')ax.grid()plt.show() 用于绘制三角函数的Python代码 (Python code for plotting trigonometric functions) import matplotlib.pyplot as pltimport numpy as np# Data for plottingt = np.arange(0.0, 24, 0.01)# Sine Plots = np.sin(t)fig, ax = plt.subplots()ax.plot(t, s)ax.set(xlabel='radians', ylabel='Sin(x)', title='Sine Plot')ax.grid()plt.show()# Cosine Plots = np.cos(t)fig, ax = plt.subplots()ax.plot(t, s)ax.set(xlabel='radians', ylabel='(cosx)', title='Cosine Plot')ax.grid()plt.show()# Tangent Plott = np.arange(0.0, 1, 0.01)s = np.tan(t)fig, ax = plt.subplots()ax.plot(t, s)ax.set(xlabel='radians', ylabel='tan(x)', title='Tangent Plot')ax.grid()plt.show()

Output:

输出:

Output is as figure

翻译自: https://www.includehelp.com/python/plotting-trigonometric-functions.aspx

python 绘制三角函数

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。