import pandas
import matplotlib.pyplot
excel=pandas.read_excel("编程语言排行榜.xlsx",sheet_name=1)#读取excel文件
print(excel)
matplotlib.pyplot.rcParams['font.sans-serif']=['SimHei']#解决中文乱码 将'font.sans-serif'设置为'SimHei' Matplotlib会使用'SimHei'来渲染中文文本。
matplotlib.pyplot.figure(figsize=(10,6))#设置画布大小
#取值
keyword=excel['编程语言']
value=excel['流行度']
print(keyword)
print(value)
matplotlib.pyplot.pie(value,labels=keyword,autopct='%1.1f%%',startangle=90)#绘制饼图 %1.1f%% 保留一位小数 startangle=90 给正角度,可有可无
matplotlib.pyplot.axis('equal')#设置x轴,y轴刻度,使饼图为一个正圆
matplotlib.pyplot.title("2024 年 7 月编程语言流行度饼图")#设置标题
matplotlib.pyplot.show()
matplotlib.pyplot.figure(figsize=(25,2))#设置画布大小
matplotlib.pyplot.bar(keyword,value,width=0.8)#绘制柱形图
matplotlib.pyplot.title("2024 年 7 月编程语言流行度树状图")#设置标题
matplotlib.pyplot.show()
matplotlib.pyplot.figure(figsize=(25,2))#设置画布大小
matplotlib.pyplot.plot(keyword,value)#绘制折线图
matplotlib.pyplot.title("2024 年 7 月编程语言流行度树状图")#设置标题
matplotlib.pyplot.show()
运行结果
数据来源于GitHub