python大数据写出Matplotlib包中pyplot模块绘制散点图、线性图、柱状图、直方图、饼图、箱线图的定义语句
时间: 2023-06-17 09:08:36 浏览: 82
以下是Matplotlib包中pyplot模块绘制各种图形的定义语句:
1. 散点图:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [6, 7, 8, 9, 10]
plt.scatter(x, y)
plt.show()
```
2. 线性图:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [6, 7, 8, 9, 10]
plt.plot(x, y)
plt.show()
```
3. 柱状图:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [6, 7, 8, 9, 10]
plt.bar(x, y)
plt.show()
```
4. 直方图:
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(1000)
plt.hist(x, bins=50)
plt.show()
```
5. 饼图:
```python
import matplotlib.pyplot as plt
labels = ['A', 'B', 'C', 'D']
sizes = [15, 30, 45, 10]
plt.pie(sizes, labels=labels)
plt.show()
```
6. 箱线图:
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(100)
plt.boxplot(x)
plt.show()
```