matplotlib plot
时间: 2023-08-13 10:10:42 浏览: 103
matplotlib.pyplot是一个Python的绘图库,它包含了一系列类似于matlab的画图函数。这些函数可以作用于当前图形(figure)的当前坐标系(axes)。\[1\]下面是一些使用matplotlib.pyplot的示例代码:
示例1:
```python
import matplotlib.pyplot as plt
y = \[0,1,4,9,16\]
line = plt.plot(y)\[0\]
line.set_color('r')
line.set_linestyle('-.')
plt.show()
```
示例2:
```python
import matplotlib.pyplot as plt
y = \[0,1,4,9,16\]
line = plt.plot(y)\[0\]
line.set(color='r',ls='-.')
plt.show()
```
示例3:
```python
import matplotlib.pyplot as plt
y = \[0,1,4,9,16\]
line = plt.plot(y)\[0\]
plt.setp(line,color='r',ls='-.')
plt.show()
```
这三种方法得到的图形是一样的。\[2\]另外,你还可以使用numpy库来生成数据,并使用matplotlib.pyplot来绘制图形。例如,下面的代码绘制了正弦函数和余弦函数的图形:
```python
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-6,6,0.1)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x,y1)
plt.plot(x,y2)
plt.show()
```
这段代码会生成一个包含正弦函数和余弦函数的图形。\[3\]
#### 引用[.reference_title]
- *1* [数据分析之Matplotlib(二)折线图(plot)](https://blog.csdn.net/qq_42642945/article/details/88320171)[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^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [matplotlib入门 ----plot()函数](https://blog.csdn.net/ckk727/article/details/100180346)[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^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文