python圆饼图代码,柱状图代码,散点图代码
时间: 2024-06-11 16:02:38 浏览: 22
好的,下面分别介绍一下Python中圆饼图、柱状图和散点图的代码。
1. 圆饼图代码:
```python
import matplotlib.pyplot as plt
# 数据
labels = ['A', 'B', 'C', 'D']
sizes = [15, 30, 45, 10]
colors = ['red', 'green', 'blue', 'yellow']
# 绘制圆饼图
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', startangle=90)
# 显示图形
plt.axis('equal')
plt.show()
```
2. 柱状图代码:
```python
import matplotlib.pyplot as plt
# 数据
x = ['A', 'B', 'C', 'D']
y = [15, 30, 45, 10]
# 绘制柱状图
plt.bar(x, y, color='blue')
# 设置标题和标签
plt.title('Bar Chart')
plt.xlabel('X-axis Label')
plt.ylabel('Y-axis Label')
# 显示图形
plt.show()
```
3. 散点图代码:
```python
import matplotlib.pyplot as plt
# 数据
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 25, 30]
# 绘制散点图
plt.scatter(x, y, color='red')
# 设置标题和标签
plt.title('Scatter Plot')
plt.xlabel('X-axis Label')
plt.ylabel('Y-axis Label')
# 显示图形
plt.show()
```
以上是Python中圆饼图、柱状图和散点图的代码,希望能对你有所帮助。如果你还有其他问题或需要更深入的解释,请随时提问。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)