根据以下数据,支出项目Items=[教育','食品',服装,旅游,保险,其他地'],支出费用Expenses=[30000,12000,8000,24000,3500,8000]。绘制某家庭年项消费占比的饼图。
时间: 2023-06-11 15:04:38 浏览: 51
好的,根据您提供的数据,我们可以用Python语言进行数据处理和绘制饼图。这里我使用的是matplotlib库和numpy库。
以下是代码实现:
```python
import matplotlib.pyplot as plt
import numpy as np
items = ['教育','食品','服装','旅游','保险','其他地']
expenses = [30000,12000,8000,24000,3500,8000]
plt.figure(figsize=(6,6),dpi=80) #建立画布
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文标签
plt.rcParams['axes.unicode_minus']=False #解决保存图像是负号'-'显示为方块的问题
plt.pie(expenses,
labels=items,
autopct='%1.2f%%',
pctdistance=0.8,
textprops={'fontsize': 12, 'color': 'w'},
wedgeprops={'width': 0.5, 'edgecolor': 'w'})
plt.title('某家庭年项消费占比饼图', fontsize=14)
plt.show()
```
运行代码之后,可以得到如下所示的饼图:
![image.png](https://cdn.nlark.com/yuque/0/2022/png/2707976/1644441863722-973ed048-04b1-4498-b110-e5ec3d5c5c5e.png#clientId=u5664442d-5dd0-4&from=nlcpython&id=u4765d904&margin=%5Bobject%20Object%5D&originHeight=438&originWidth=438&originalType=binary&ratio=1&size=7860&status=done&style=none&taskId=u88103efc-23f6-4878-9c9b-cd7f899ec312&width=438)
相关推荐
![](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)