import matplotlib.pyplot as plt import matplotlib matplotlib.use('TkAgg') # 設定函式進行計算 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 SAC = 10 BAC = 170 pv = [] ac = [] ev = [] cv = [] sv = [] cpi = [] spi = [] teac = [] eac = [] # 1st week ac.append(10) pv.append(10) ev.append(30 * 0.3) sv.append(SV(ev[0], pv[0])) cv.append(CV(ev[0], ac[0])) spi.append(SPI(ev[0], pv[0])) cpi.append(CPI(ev[0], ac[0])) teac.append(TEAC(SAC, spi[0])) eac.append(EAC(BAC, cpi[0])) print(ac, pv, spi, teac, eac) # 2ed week ac.append(36) pv.append(35) ev.append(30 * 0.8 + 70 * 0.1) sv.append(SV(ev[1], pv[1])) cv.append(CV(ev[1], ac[1])) spi.append(SPI(ev[1], pv[1])) cpi.append(CPI(ev[1], ac[1])) teac.append(TEAC(SAC, spi[1])) eac.append(EAC(BAC, cpi[1])) print(ac, pv, spi, teac, eac) # 3ird week ac.append(54) pv.append(50) ev.append(30 + 70 * 0.25) sv.append(SV(ev[2], pv[2])) cv.append(CV(ev[2], ac[2])) spi.append(SPI(ev[2], pv[2])) cpi.append(CPI(ev[2], ac[2])) teac.append(TEAC(SAC, spi[2])) eac.append(EAC(BAC, cpi[2])) print(ac, pv, spi, teac, eac) pvList = pv acList = ac evList = ev x_data = ['1st week', '2ed week', '3ird week'] plt.plot(x_data, pvList, ':o', alpha=1, linewidth=1, label='PV') plt.plot(x_data, acList, '--x', alpha=1, linewidth=1, label='AC') plt.plot(x_data, evList, '-.s', alpha=1, linewidth=1, label='EV') plt.legend() plt.xlabel('time/week') plt.ylabel('value') plt.show()