import math
from matplotlib import cm
import matplotlib.pyplot as plt
import matplotlib.ticker as mt
import numpy as np
import pandas as pd
d = {'New': [0, 1/12],
'1 m old': [0, 0],
'2 m old': [0, 0],
'3 m old': [0, 0],
'4 m old': [0, 0],
'5 m old': [0, 0],
'6 m old': [0, 0],
'7 m old': [0, 0],
'8 m old': [0, 0],
'9 m old': [0, 0],
'10 m old': [0, 0],
'11 m old': [0, 0],
'Old': [1, 11/12],}
transmission = pd.DataFrame(d)
for m in range(2, 14):
#New month, and 1/12 is new transmission.
new_month = [1/12]
#All last month data.
last_month = transmission.iloc[-1]
for o in range(1,12):
#11/12 of the oil ages by 1 month.
new_month.append(last_month[o-1]*11/12)
#Old transmission is the 11th month old*11/12 of last month and all old oil minus 1/12th removed.
old = (last_month[11] + last_month[12]) * 11/12
new_month.append(old)
#Update transmission dataframe
transmission_new = pd.DataFrame([new_month], columns=list(transmission.columns))
transmission = transmission.append(transmission_new, ignore_index=True)
transmission
New | 1 m old | 2 m old | 3 m old | 4 m old | 5 m old | 6 m old | 7 m old | 8 m old | 9 m old | 10 m old | 11 m old | Old | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 1.000000 |
1 | 0.083333 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 0.916667 |
2 | 0.083333 | 0.076389 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 0.840278 |
3 | 0.083333 | 0.076389 | 0.070023 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 0.770255 |
4 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 0.706067 |
5 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 0.647228 |
6 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.053936 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 0.593292 |
7 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.053936 | 0.049441 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 0.543851 |
8 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.053936 | 0.049441 | 0.045321 | 0.000000 | 0.000000 | 0.000000 | 0.000 | 0.498530 |
9 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.053936 | 0.049441 | 0.045321 | 0.041544 | 0.000000 | 0.000000 | 0.000 | 0.456986 |
10 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.053936 | 0.049441 | 0.045321 | 0.041544 | 0.038082 | 0.000000 | 0.000 | 0.418904 |
11 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.053936 | 0.049441 | 0.045321 | 0.041544 | 0.038082 | 0.034909 | 0.000 | 0.383995 |
12 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.053936 | 0.049441 | 0.045321 | 0.041544 | 0.038082 | 0.034909 | 0.032 | 0.351996 |
13 | 0.083333 | 0.076389 | 0.070023 | 0.064188 | 0.058839 | 0.053936 | 0.049441 | 0.045321 | 0.041544 | 0.038082 | 0.034909 | 0.032 | 0.351996 |
fig = plt.figure()
fig.set_figheight(8)
fig.set_figwidth(13)
ax = fig.add_subplot(1,1,1)
ax.margins(x=0)
transmission.plot(ax = ax,
kind = "barh",
stacked = True,
cmap = 'viridis_r',
width = 0.95)
ax.set_title("Age Of Transmission Fluid Over Time", fontsize = 24)
ax.set_xlabel("Fraction of Transmission Fluid", fontsize = 20)
ax.xaxis.set_major_formatter(mt.PercentFormatter(1.0))
plt.xticks(fontsize = 16)
ax.set_ylabel("Month", fontsize = 20)
ax.invert_yaxis()
plt.yticks(fontsize = 16)
ax.legend(loc = 'center right',
bbox_to_anchor = (1.08, 0.5),
ncol = 1,
fancybox = True,
shadow = True);
fig.savefig("2022.01.28 Classic.png")