目录
1、 导入相关的包。
2、读取excel文件,提取语文的数据。
3、 画柱状图的代码。
4、完整代码:
5、效果图:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel(r'C:\Users\Administrator\Desktop\cj.xlsx',sheet_name='Sheet1') data = df.iloc[:, [2]].values
grade = [1,1,5,3,2] plt.figure() A = ['<60', '60-70', '70-80', '80-90','>90'] plt.pie(grade, labels=A, autopct='%1.1f%%') plt.title('Grade') plt.show()
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel(r'C:\Users\Administrator\Desktop\cj.xlsx',sheet_name='Sheet1')
data = df.iloc[:, [2]].values
print(data)
grade = [1,1,5,3,2]
plt.figure()
A = ['<60', '60-70', '70-80', '80-90','>90']
plt.pie(grade, labels=A, autopct='%1.1f%%')
plt.title('Grade')
plt.show()