from pylab import
import numpy as np
import matplotlib.pyplot as plt
import xlrd
import matplotlib as mpl
mpl.rcParams['font.sans-serif']=['SimHei']
workbook = xlrd.open_workbook(r'C:\Users\Desktop\a.xlsx')
worksheets = workbook.sheet_names()
#mySheet = workbook.sheet_by_name(u'pressure')
mySheet = workbook.sheet_by_name(worksheets[0])
pressure = mySheet.col_values(0)
time = mySheet.col_values(1)
man = mySheet.col_values(2)
pressure.pop(0)
time.pop(0)
man.pop(0)
fig = plt.figure(figsize=(10,4))
tol = np.array(pressure) + np.array(man)
a = []
for i in range(len(tol)):
per = pressure[i] / tol[i]
100
a.append(per)
i += 1
​-
b = []
for x in range(len(tol)):
per2 = man[x] / tol[x] * 100
b.append(per2)
x += 1

for i,j in zip(np.array(time),a):
plt.text(i,j+0.005,'%.0f%%' % j,ha='center',va='bottom',fontsize=12)
plt.plot(np.array(time),np.array(a),linestyle='-',color='green',label="manual",marker='o',markersize=7)
for q,w in zip(np.array(time),b):
plt.text(q,w+0.005,'%.0f%%' % w,ha='center',va='bottom',fontsize=12)
plt.plot(np.array(time),np.array(b),linestyle='-',color='yellow',linewidth=3,label="system")
#legend(loc='upper right')
plt.title('事件总数')
plt.ylabel('Per')
plt.xlabel('Month')

ya = ['10%','20%','30%','40%','50%','60%','70%','80%','90%','100%']
plt.xticks(np.array(time),fontsize=13)
plt.yticks(np.arange(0,110,10),ya[0:10])
legend(loc='lower right',ncol=2)
plt.grid(axis='y',color='black',alpha=0.3)
plt.show()

Xlrd,Numpy,Matplotlib_第1张图片