饼图示例
效果图

"""
Created on Mon Oct 18 15:34:53 2021
@author: luoha
"""import pandas as pd
import matplotlib.pyplot as plt
import numpy as npimport pandas as pd
import matplotlib.pyplot as plt
users = pd.read_excel('E:\SXFEL\others\绘图\人数分类(1).xlsx')
print(users)
users.sort_values(by="number",inplace=True,ascending=False)
print(users)
df = users
labels = [] allpeople = sum(df['number'])for i , k in zip(df['people'],df['number']):j = i + "(" + str('{:.2%}'.format(k/allpeople)) + ")"labels.append(j)sizes = df['number']
rangestart = 2
colors = [plt.cm.Spectral(i/float(len(labels))) for i in range(rangestart,rangestart+len(labels))]
x=0; y=0
width = 2; height = 1
fig, ax = plt.subplots(1, figsize=(15, 15 * height / width))
ax.set_xlim(x, width)
ax.set_ylim(y, height)
patches, texts = plt.pie(x=sizes,labels=labels,colors=colors,startangle=0,rotatelabels=False, wedgeprops={'edgecolor':'w','width':0.7, 'linewidth':2})
plt.title('YYDS',fontweight='bold',fontsize='18',color='green')
plt.ylabel('YYDS',fontweight='bold',fontsize='16',color='green')plt.legend(patches, labels,title="YYDS Pie",loc="center left",bbox_to_anchor=(0.9, 0.7, 0.5, 0.5),ncol=2,)plt.show()
plt.savefig("E:\SXFEL\others\绘图\PieChart7.png")
plt.savefig("E:\SXFEL\others\绘图\PieChart7.svg",format = 'svg')
表格内容
| people | number |
|---|
| Speaker | 89 |
| Poster Presenters | 174 |
| Delegate | 257 |
| Exhibitors | 21 |
| Organizers / Staff | 9 |
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!