You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
2.4 KiB
45 lines
2.4 KiB
3 years ago
|
import matplotlib.pyplot as plt
|
||
|
import numpy as np
|
||
|
import json
|
||
|
|
||
|
with open("ecar.json", "r") as rf:
|
||
|
settings = json.load(rf)
|
||
|
|
||
|
kilometer_price = np.array( [settings["ecar"]["kwh_per_kilometer"] * settings["kwh_price_home"],
|
||
|
settings["ccar"]["litre_per_kilometer"] * settings["petrol_litre_price"]])
|
||
|
labels = [settings["ecar"]["label"], settings["ccar"]["label"]]
|
||
|
price = np.array([settings["ecar"]["price"], settings["ccar"]["price"]])
|
||
|
taxes = np.array([settings["ecar"]["taxes"], settings["ccar"]["taxes"]])
|
||
|
insurance = np.array([settings["ecar"]["insurance"], settings["ccar"]["insurance"]])
|
||
|
kilometer_price_ecar = (settings["ecar"]["charging_behaviour"]["percent_home_charges"] * settings["kwh_price_home"]
|
||
|
+ settings["ecar"]["charging_behaviour"]["percent_commercial_charges"] * settings["kwh_price_commercial"]) / 100.0
|
||
|
driving = np.array([kilometer_price_ecar * settings["kilometers_per_year"], kilometer_price[1] * settings["kilometers_per_year"]])
|
||
|
maintenance = np.array([settings["ecar"]["maintenance"], settings["ecar"]["maintenance"]])
|
||
|
width = 0.3
|
||
|
|
||
|
fig, ax = plt.subplots()
|
||
|
ax.bar(labels, price, width, label = "Price", color = "gray")
|
||
|
currenty = price
|
||
|
y = 0
|
||
|
|
||
|
for i in range(settings["years"]):
|
||
|
#while currenty[0] > currenty[1]:
|
||
|
ax.bar(labels, taxes, width, bottom = currenty, label = "Taxes".format(y), color = "darkgreen")
|
||
|
currenty = currenty + taxes
|
||
|
ax.bar(labels, insurance, width, bottom = currenty, label = "Insurance".format(y), color = "royalblue")
|
||
|
currenty = currenty + insurance
|
||
|
ax.bar(labels, driving, width, bottom = currenty, label = "Driving".format(y), color = "midnightblue")
|
||
|
currenty = currenty + driving
|
||
|
ax.bar(labels, maintenance, width, bottom = currenty, label = "Maintenance".format(y), color = "lavender")
|
||
|
currenty = currenty + maintenance
|
||
|
y += 1
|
||
|
ecar_top = currenty[0]
|
||
|
#ax.plot(np.linspace(-0.2, 1.2, 10), [ecar_top]*10, "--", color = "firebrick", label = "Break even")
|
||
|
ax.text(0.3, ecar_top * 0.95, "Break even: {} years, {} kilometers".format(y, y*settings["kilometers_per_year"]))
|
||
|
ax.set_ylabel("CHF")
|
||
|
ax.set_title("Comparision of economics electric vs. combustion car")
|
||
|
ax.legend(["Price", "Taxes", "Insurance", "Driving", "Maintenance"])
|
||
|
ax.grid(axis = "y")
|
||
|
print("Break even after {} years and {} kilometers. {}, {}".format(y, y*settings["kilometers_per_year"], currenty[0], currenty[1]))
|
||
|
plt.show()
|