# Agregue años anteriores si tiene tiempoimportar numpy como np importar matplotlib.pyplot como plt import syslang = "en" #lang = "tr"# Datos de https://enerji.gov.tr/enerji-isleri-genel-mudurlugu-denge-tablolari Hoja: BİN TEP yyyy Fila 12: ENERJİ ÜRÜNLERİ ARZI año = [ '2016' , '2017' , '2018' , '2019' ]Taş_Kömürü = [ 23597 , 24707 , 24679 , 25120 ] Linyit = [ 13556 , 13791 , 15086 , 15453 ] Asfaltit = [ 778 , 555 , 697 , 1022 ] Kok = [ 527 , 504 , 513 , 420 ] # combinar diferentes tipos de carbón # No se pudo ver cómo agregar más de 2 matrices Kömür = np .añadir ( Taş_Kömürü , Linyit ) . tolist () Kömür = np . añadir ( Kömür , Asfaltit ) . tolist () Kömür = np . añadir ( Kömür , Kok ) . tolist ()Ham_Petrol = [ 28709 , 29491 , 25099 , 35448 ] Petrol_Ürünleri = [ 13495 , 14786 , 16814 , 6006 ] # Combinar diferentes tipos de aceite Gasolina = np . añadir ( Ham_Petrol , Petrol_Ürünleri ) . tolist ()Doğalgaz = [ 38338 , 44319 , 41171 , 37128 ] Biyoenerji_ve_Atıklar = [ 2843 , 2531 , 3014 , 3157 ] Hidrolik = [ 5782 , 5007 , 5155 , 7639 ] Rüzgar = [ 1334 , 1540 , 1716 , 1869 ] Jeotermal = [ 6034 , 7128 , 8343 , 9651 ] Güneş = [ 917 , 1091 , 1547 , 1622 ]# Convierta a megatoneladas para que sea más fácil de leercarbón = np . dividir ( Kömür , 1000 ) . aceite tolist () = np . dividir ( gasolina , 1000 ) . gas tolist () = np . dividir ( Doğalgaz , 1000 ) . tolist () bio_and_waste = np . dividir ( Biyoenerji_ve_Atıklar , 1000 ) . tolist () hidro = np . dividir ( Hidrolik , 1000 ) . tolist () viento = np . dividir ( Rüzgar , 1000 ) . tolist () geotermal = np . dividir ( Jeotermal , 1000 ) . tolist () solar = np . dividir ( Güneş , 1000 ) . tolist ()# Establecer el tamaño de fuente como predeterminado era un poco pequeño para leer fontsize = 14if lang == "en" : plt . título ( "suministro de energía primaria en Turquía" , FontSize = tamaño de fuente ) plt . ylabel ( "Megatoneladas equivalentes de petróleo" ) etiquetas = [ "carbón" , "petróleo" , "gas" , "bioandwaste" , "hidro" , "viento" , "geotermia" , "solar" ] elif lang == "tr" : plt . título ("Necesita traducción" , FontSize = tamaño de fuente ) plt . ylabel ( "Megatonne ??????" ) labels = [ "Kömür" , "Petrol" , "Doğalgaz" , "Biyoenerji_ve_Atıklar" , "Hidrolik" , "Rüzgar" , "Jeotermal" , "Güneş" ] más : imprimir ( "Idioma desconocido" + lang ) sys . salir ()colores = [ "marrón" , "negro" , "caqui" , "verde" , "azul" , "rosa" , "rojo" , "amarillo" ] plt . diagrama de pila ( año , carbón , petróleo , gas , bio_y_waste , hidro , eólico , geotermal , solar , etiquetas = etiquetas , colores = colores )# Obtener asas y etiquetas actuales # esto debe hacerse después de trazar current_handles , CURRENT_LABELS = PLT . gca () . get_legend_handles_labels ()# Reordenar las etiquetas y asas para colores en mismo orden que grapph reversed_handles = lista ( invertidas ( current_handles )) reversed_labels = lista ( invertidas ( CURRENT_LABELS ))# llamar a plt.legend () con los nuevos valores plt . leyenda ( tiradores_inversos , etiquetas_invertidas , loc = "parte inferior izquierda" )# Guardar plt gráfico . savefig ( 'energía_primaria_Turquía.svg' ) # Mostrar plt gráfico . mostrar ()# El gráfico resultante debería ser más o menos similar al gráfico "Suministro total de energía primaria (TPES) por fuente, Turquía" # de https://www.iea.org/data-and-statistics, pero tal vez no sea exactamente el mismo si Turkstat ha revisado sus cifras