lang = "en"
#lang = "tr"
#graph_type = "stack"
graph_type = "line"
import numpy as np
import matplotlib.pyplot as plt
import sys
import seaborn as sns
# When adding new year also update number of xticks as well as year at end, and both Turkish and English source year (or make code cleverer so less updates needed)
# Data from https://unfccc.int/ghg-inventories-annex-i-parties/2022 National Inventory Report: Table 3.10 CO2 emissions from fuel combustion: Sectoral Approach
ghg_oil_kt = [59775, 58433, 62934, 72870, 70321, 77720, 81746, 81515, 77139, 78484, 82159, 77821, 79708, 81317, 85186, 83332, 81906, 86422, 85180, 82584, 78708, 81391, 87092, 91718, 96257,105439,114082,116300,113524, 111111, 112903]
ghg_coal_kt = [63172, 67539, 68552, 63995, 62993, 65272, 76505, 84429, 87610 ,78236, 92771, 78707, 81652, 85950, 86660, 95196,104396,118279,114783,122257,120683,125204,131041,114701,119749,128006,139842,145912,150431, 154271, 148138]
ghg_gas_kt = [ 6716, 8265, 9036, 10074, 10585, 13626, 15918, 19879, 20655, 25848, 29371, 31937, 33875, 42260, 43265, 53664, 61441, 71405, 70824, 70744, 70832, 84554, 85351, 85182, 91869, 94370, 89708,102693, 93478, 81159, 89835]
year = ('1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020')
#Labelling all the years is a bit busy so just label some
plt.xticks([0,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], ['1990','','','','','1995','','','','','2000','','','','','2005','','','','','2010','','','','','2015','','','','','2020','2021'])
# Convert kilotonnes to megatonnes as easier to read
ghg_oil = np.divide(ghg_oil_kt, 1000).tolist()
ghg_coal = np.divide(ghg_coal_kt, 1000).tolist()
ghg_gas = np.divide(ghg_gas_kt, 1000).tolist()
color_oil = "black"
color_coal = "brown"
color_gas = "khaki"
colors = (color_coal,color_oil,color_gas)
if lang == "en":
plt.title ("Carbon dioxide emitted by fossil fuels burnt in Turkey",fontsize = 'x-large')
plt.ylabel("Million tonnes")
plt.xlabel('Source: https://unfccc.int/ghg-inventories-annex-i-parties/2022', fontsize = 'x-small', color = 'grey')
label_coal = "coal"
label_oil = "oil"
label_gas = "gas"
elif lang == "tr":
plt.title ("Türkiye'de fosil yakıttan atmosfere giden karbondioksit",fontsize = 'x-large')
plt.ylabel("Megatonne")
plt.xlabel('Kaynak: https://unfccc.int/ghg-inventories-annex-i-parties/2022', fontsize = 'x-small', color = 'grey')
label_coal = "Kömür"
label_oil = "Petrol"
label_gas = "Doğalgaz"
else:
print("Unknown language: " + lang)
sys.exit()
if graph_type == "stack":
plt.stackplot(year, ghg_coal, ghg_oil, ghg_gas, colors=colors)
elif graph_type == "line":
plt.plot(year, ghg_coal, color=color_coal)
plt.plot(year, ghg_oil, color=color_oil)
plt.plot(year, ghg_gas, color=color_gas)
else:
print("Unknown graph type: " + graph_type)
sys.exit()
# Position labels manually to make them quicker to read than a legend in a corner - might need slight adjustment as years added
if graph_type == "stack":
plt.text(24, 65,label_coal,fontsize = 'x-large')
plt.text(24,175,label_oil, fontsize = 'x-large', color="white")
plt.text(24,280,label_gas, fontsize = 'x-large')
elif graph_type == "line":
plt.text(31,145,label_coal,fontsize = 'large')
plt.text(31,110,label_oil, fontsize = 'large')
plt.text(31, 90,label_gas, fontsize = 'large')
else:
print("Unknown graph type: " + graph_type)
sys.exit()
#Avoid chopping off labels
plt.tight_layout()
#Avoid squashing up years
#plt.xticks(rotation=90)
#Don't need the frame
sns.despine(bottom = True, left = True)
#Don't need the dash marks
plt.tick_params(left=False, bottom=False)
# Save graphic
if graph_type == "stack":
if lang == "en":
plt.savefig("fossil_fuel_CO2_Turkey.svg")
elif lang == "tr":
plt.savefig("fosil_yakıt_CO2_Türkiye.svg")
else:
print("Unknown language " + lang)
sys.exit()
elif graph_type == "line":
if lang == "en":
plt.savefig("fossil_fuel_CO2_Turkey_line_graph.svg")
elif lang == "tr":
plt.savefig("fosil_yakıt_CO2_Türkiye_çizgi grafiği.svg")
else:
print("Unknown language " + lang)
sys.exit()
else:
print("Unknown graph type: " + graph_type)
sys.exit()
# Show graphic
plt.show()