请你用python在一块画布上绘制4幅图,分别是曲线图、直方图、饼图、折线图,数据自己定义
时间: 2023-04-08 07:01:12 浏览: 114
好的,我可以回答这个问题。以下是使用Python绘制4种不同类型图表的示例代码:
曲线图:
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Sine Curve')
plt.show()
```
直方图:
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.random.normal(size=1000)
plt.hist(x, bins=30)
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Histogram')
plt.show()
```
饼图:
```python
import matplotlib.pyplot as plt
labels = ['Apples', 'Oranges', 'Bananas', 'Pears']
sizes = [30, 25, 20, 15]
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.axis('equal')
plt.title('Fruit Distribution')
plt.show()
```
折线图:
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y1, label='Sine')
plt.plot(x, y2, label='Cosine')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Sine and Cosine Curves')
plt.legend()
plt.show()
```
希望这些示例代码能够帮助你绘制出自己的图表。
阅读全文