python 画sin曲线
时间: 2023-10-17 14:32:03 浏览: 147
要使用Python画sin曲线,可以使用NumPy和Matplotlib库。以下是一个示例代码:
```
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2 * np.pi, 100) [1]
y = np.sin(x)
plt.plot(x, y)
plt.show() [2]
```
在这个代码中,首先导入了NumPy和Matplotlib库。然后,使用`np.linspace`函数生成一组从0到2π的100个均匀间隔的数值,作为x轴的取值范围。接下来,使用NumPy的`np.sin`函数计算出对应x轴取值的sin函数值并赋给y。最后,使用Matplotlib的`plt.plot`函数将x和y作为参数绘制出sin曲线,并使用`plt.show`函数显示出图形。
你可以在网站https://www.cnblogs.com/jmlovepython/p/5673088.html找到完整的代码和更多细节。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [python 画函数曲线示例](https://download.csdn.net/download/weixin_38698927/13761671)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [python 画正弦曲线](https://blog.csdn.net/babude2008/article/details/101656312)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文