具体代码
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei'] # 指定默认字体:解决plot不能显示中文问题
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
# 设定函数进行计算
def SV(EV, PV):
return EV-PV
def CV(EV,AC):
return EV-AC
def SPI(EV,PV):
return EV/PV
def CPI(EV,AC):
return EV/AC
def TEAC(SAC,SPI):
return SAC/SPI
def EAC(BAC,CPI):
return BAC/CPI
# 存储用得上的数据
PV1 = [30, 10, 15, 5]
PV2 = [70, 0, 10, 10]
AC1 = [10, 16, 8]
AC2 = [0, 10, 10]
EV1 = [30, 80, 100]
EV2 = [0, 10, 25]
# 第一周
pv1 = PV1[1]+PV2[1]
ac1 = AC1[0]+AC2[0]
ev1 = PV1[0]*EV1[0]*0.01+PV2[0]*EV2[0]*0.01
sv1 = SV(ev1, pv1)
cv1 = CV(ev1, ac1)
spi1 = SPI(ev1, pv1)
cpi1 = CPI(ev1, ac1)
teac1 = TEAC(10, spi1)
eac1 = EAC(170, cpi1)
# 第二周
pv2 = PV1[2]+PV2[2]+pv1
ac2 = AC1[1]+AC2[1]+ac1
ev2 = PV1[0]*EV1[1]*0.01+PV2[0]*EV2[1]*0.01
sv2 = SV(ev2, pv2)
cv2 = CV(ev2, ac2)
spi2 = SPI(ev2, pv2)
cpi2 = CPI(ev2, ac2)
teac2 = TEAC(10, spi2)
eac2 = EAC(170, cpi2)
# 第三周
pv3 = PV1[3]+PV2[3]+pv2
ac3 = AC1[2]+AC2[2]+ac2
ev3 = PV1[0]*EV1[2]*0.01+PV2[0]*EV2[2]*0.01
sv3 = SV(ev3, pv3)
cv3 = CV(ev3, ac3)
spi3 = SPI(ev3, pv3)
cpi3 = CPI(ev3, ac3)
teac3 = TEAC(10, spi3)
eac3 = EAC(170, cpi3)
# 将得到的数据存储为列表
pvList = []
pvList.append(pv1)
pvList.append(pv2)
pvList.append(pv3)
acList = []
acList.append(ac1)
acList.append(ac2)
acList.append(ac3)
evList = []
evList.append(ev1)
evList.append(ev2)
evList.append(ev3)
x_data = ['第一周', '第二周', '第三周']
plt.plot(x_data, pvList, 'p--', alpha=0.5, linewidth=1, label='PV') # 'bo-'表示蓝色实线,数据点实心原点标注
## plot中参数的含义分别是横轴值,纵轴值,线的形状('s'方块,'o'实心圆点,'*'五角星 ...,颜色,透明度,线的宽度和标签 ,
plt.plot(x_data, acList, '*--', alpha=0.5, linewidth=1, label='AC')
plt.plot(x_data, evList, '+--', alpha=0.5, linewidth=1, label='EV')
plt.legend() # 显示上面的label
plt.xlabel('时间/周') # x_label
plt.ylabel('值') # y_label
# plt.ylim(-1,1)#仅设置y轴坐标范围
plt.show()
效果展示