-
Notifications
You must be signed in to change notification settings - Fork 0
/
taxi.py
78 lines (59 loc) · 2.12 KB
/
taxi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
A Python script for manipulating the CSV data returned by `taxify.go`.
* This script accepts CLI arguments in the same format as the Go file.
As such, it can decode them in the same way and access the exact CSV
file that was created by the Go program, given the same inputs.
"""
import argparse
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation, FFMpegFileWriter
def main(args: list) -> None:
df = pd.read_csv(get_filepath(args.income, args.steps))
plot(df)
# animate(df, top=7)
def plot(df: pd.DataFrame, top: int = 53) -> None:
top = max(0, min(df.shape[1], top))
for i in range(1, df.shape[0]):
for j in range(1, top):
plt.plot(df["income"].iloc[:i], df.iloc[:i, j])
plt.xlim([0, df["income"].iloc[-1]])
plt.ylim([0, 0.38])
plt.title(df["income"].iloc[i])
plt.xlabel("Income")
plt.ylabel("Effective tax rate")
# plt.savefig(f"./output/plots/demo/{i}.png")
plt.show()
def animate(df: pd.DataFrame, top: int = 10) -> None:
top = max(0, min(df.shape[1], top))
plt, ax = plt.subplots()
plt.xlim([0, df["income"].iloc[-1]])
plt.ylim([0, 0.38])
plt.title(df["income"].iloc[i])
plt.xlabel("Income")
plt.ylabel("Effective tax rate")
ax.plot(df["income"].iloc[:i], df.iloc[:i, j])
plt.show()
def add_data(plt: object, df: pd.DataFrame) -> object:
plt.set_ydata(np.sin(x + i / 50)) # update the data.
return plt
ani = animation.FuncAnimation(fig, animate, interval=20, blit=True, save_count=50)
def get_filepath(income: int, steps: int) -> str:
"""generate the dynamic filepath givent the inputs"""
return f"./output/csv/income={income}_steps={steps}.csv"
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-income",
type=int,
required=True,
help="income (type <int>), digits only, used in the CSV",
)
parser.add_argument(
"-steps",
type=int,
required=True,
help="number of steps (type <int>) used in the CSV",
)
args = parser.parse_args()
main(args)