{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "4672efe0-c2c6-4111-adb7-ffc9f567b3fc", "metadata": {}, "outputs": [], "source": [ "import sys\n", "import csv\n", "import matplotlib\n", "import numpy as np\n", "import pandas as pd\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "id": "f15bd9a4-f093-47a7-b506-56e2c16ab08a", "metadata": {}, "outputs": [], "source": [ "plt.style.use('default')" ] }, { "cell_type": "code", "execution_count": null, "id": "d5f15d57-af6a-48d7-99d2-29a5e2546827", "metadata": {}, "outputs": [], "source": [ "data = pd.read_excel(\"1. Oil production_1900-2023.xlsx\", sheet_name=\"Latin America (TWh)\", header=2)\n", "data.rename(columns={'Unnamed: 0': 'year'}, inplace=True)" ] }, { "cell_type": "markdown", "id": "5753a78a-0da4-40ce-820c-b874ba69229f", "metadata": {}, "source": [ "# Countries of AL - TWh by year" ] }, { "cell_type": "code", "execution_count": null, "id": "d5c96c89-e2e5-4b45-89d3-46276efbe208", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize = (20,10))\n", "\n", "ax.plot(data[\"year\"], data[\"Bolivia\"], label=\"Bolivia\")\n", "ax.plot(data[\"year\"], data[\"Argentina\"], label=\"Argentina\") \n", "ax.plot(data[\"year\"], data[\"Colombia\"], label=\"Colombia\") \n", "ax.plot(data[\"year\"], data[\"Brazil\"], label=\"Brazil\") \n", "ax.plot(data[\"year\"], data[\"Peru\"], label=\"Peru\") \n", "ax.plot(data[\"year\"], data[\"Ecuador\"], label=\"Ecuador\") \n", "ax.plot(data[\"year\"], data[\"Mexico\"], label=\"Mexico\") \n", "ax.plot(data[\"year\"], data[\"Trinidad & Tobago\"], label=\"Trinidad & Tobago\") \n", "ax.plot(data[\"year\"], data[\"Venezuela\"], label=\"Venezuela\") \n", "\n", "ax.set_xlabel(\"Year\")\n", "ax.set_ylabel(\"Terawatt hours\")\n", "ax.set_title(\"Latin American oil production in terawatt hours by country (all countries)\")\n", "\n", "plt.legend(loc=\"upper left\")\n", "plt.savefig(\"twh_year_all.png\")" ] }, { "cell_type": "code", "execution_count": null, "id": "5e77285c-66a5-433e-9b27-6f5ad3ca6f66", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize = (20,10))\n", "\n", "ax.plot(data[\"year\"], data[\"Bolivia\"], label=\"Bolivia\")\n", "ax.plot(data[\"year\"], data[\"Peru\"], label=\"Peru\") \n", "ax.plot(data[\"year\"], data[\"Trinidad & Tobago\"], label=\"Trinidad & Tobago\") \n", "\n", "ax.set_xlabel(\"Year\")\n", "ax.set_ylabel(\"Terawatt hours\")\n", "ax.set_title(\"Latin American oil production in terawatt hours by country (lower tercile)\")\n", "\n", "plt.legend(loc=\"upper left\")\n", "plt.savefig(\"twh_year_low.png\")" ] }, { "cell_type": "code", "execution_count": null, "id": "f55674a3-3c59-484a-936b-5c5c4fc7a513", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize = (20,10))\n", "\n", "ax.plot(data[\"year\"], data[\"Argentina\"], label=\"Argentina\") \n", "ax.plot(data[\"year\"], data[\"Colombia\"], label=\"Colombia\") \n", "ax.plot(data[\"year\"], data[\"Ecuador\"], label=\"Ecuador\") \n", "\n", "ax.set_xlabel(\"Year\")\n", "ax.set_ylabel(\"Terawatt hours\")\n", "ax.set_title(\"Latin American oil production in terawatt hours by country (median tercile)\")\n", "\n", "plt.legend(loc=\"upper left\")\n", "plt.savefig(\"twh_year_middle.png\")" ] }, { "cell_type": "code", "execution_count": null, "id": "da968ad0-7b19-4715-b776-44b990d12d0e", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize = (20,10))\n", "\n", "ax.plot(data[\"year\"], data[\"Brazil\"], label=\"Brazil\") \n", "ax.plot(data[\"year\"], data[\"Mexico\"], label=\"Mexico\") \n", "ax.plot(data[\"year\"], data[\"Venezuela\"], label=\"Venezuela\") \n", "\n", "ax.set_xlabel(\"Year\")\n", "ax.set_ylabel(\"Terawatt hours\")\n", "ax.set_title(\"Latin American oil production in terawatt hours by country (higher tercile)\")\n", "\n", "plt.legend(loc=\"upper left\")\n", "plt.savefig(\"twh_year_high.png\")" ] }, { "cell_type": "markdown", "id": "3fcb63c7-76ed-4171-ae30-8bdd5f68bf17", "metadata": {}, "source": [ "# World versus AL : percentage of TWh by year" ] }, { "cell_type": "code", "execution_count": null, "id": "de9e3c12-e16c-498a-8539-526b248e2113", "metadata": {}, "outputs": [], "source": [ "alpercent = data[[\"year\", \"Total AL\", \"World Total\"]]\n", "alpercent.rename(columns={\"Total AL\": \"al\", \"World Total\": \"world\"}, inplace=True)\n", "alpercent[\"al_percent\"] = alpercent[\"al\"] * 100 / alpercent[\"world\"]\n", "alpercent[\"world_percent\"] = 100 - alpercent[\"al_percent\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "b71346a3-909f-4336-b34a-7700696d999b", "metadata": {}, "outputs": [], "source": [ "alpercent[\"labels\"] = alpercent[\"al_percent\"].round(2).astype(str) + \"%\"\n", "data_total_labels = list(alpercent[\"labels\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "7ca8e278-3c63-4b1a-89c0-cc28880c766f", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize = (8,42))\n", "ax.set_ylim(2024, 1899)\n", "ax.set_xlim(0, 100)\n", "\n", "ax.barh(alpercent[\"year\"], alpercent[\"al_percent\"], height=0.5, color=\"#194d19\", label=\"Latin America\")\n", "ax.barh(alpercent[\"year\"], alpercent[\"world_percent\"], left=alpercent[\"al_percent\"], height=0.5, color=\"#b3e6b3\", label=\"World\")\n", "\n", "ax.bar_label(ax.containers[0], labels=data_total_labels,\n", " padding=8, fontsize=9)\n", "\n", "ax.bar_label(ax.containers[1], labels=alpercent[\"world\"].round(0).astype(int).astype(str) + \" TWh\",\n", " padding=-80, fontsize=9)\n", "\n", "ax.set_xlabel(\"Percentage of TWh production\")\n", "ax.set_ylabel(\"Year\")\n", "ax.set_title(\"Latin America's share of the world oil production\")\n", "\n", "plt.legend(loc=\"upper center\")\n", "plt.savefig(\"world_percentage.png\")" ] }, { "cell_type": "markdown", "id": "61e17087-4c68-43b2-8724-cdf088210839", "metadata": {}, "source": [ "# Energy trade balance" ] }, { "cell_type": "code", "execution_count": null, "id": "f44af8bf-7787-4446-8feb-b57896e1337e", "metadata": {}, "outputs": [], "source": [ "trade = pd.read_excel(\"5. Energy trade_1971-2015.xlsx\", sheet_name=\"LA, Energy trade, 1971-2015\", header=1)\n", "trade.rename(columns={'Unnamed: 0': 'year', \"Unnamed: 1\": \"trade\"}, inplace=True)\n", "trade[\"percentage\"] = trade[\"trade\"].astype(float).abs().round(2)\n", "trade.loc[44, \"percentage\"] = -6.61" ] }, { "cell_type": "code", "execution_count": null, "id": "69172d80-51db-4540-9051-68c3e05216d4", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize = (20,10))\n", "ax.set_ylim(-10, 80)\n", "plt.axhline(y=0, color='black', linestyle='-', lw=0.5)\n", "\n", "ax.bar(trade[\"year\"], trade[\"percentage\"], color=\"#b3e6b3\", label=\"Latin America\")\n", "#ax.barh(alpercent[\"year\"], alpercent[\"world_percent\"], left=alpercent[\"al_percent\"], height=0.5, color=\"#194d19\", label=\"World\")\n", "\n", "ax.bar_label(ax.containers[0], labels=trade[\"percentage\"].round(0).astype(int).astype(str) + \"%\",\n", " padding=5, fontsize=9)\n", "\n", "ax.set_xlabel(\"Year\")\n", "ax.set_ylabel(\"Percentage of energy imported\")\n", "ax.set_title(\"Energy trade in Latin America, as percentage of use, 1971-2015\")\n", "\n", "plt.legend(loc=\"upper center\")\n", "plt.savefig(\"trade_balance.png\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.9" } }, "nbformat": 4, "nbformat_minor": 5 }