anthroposouth/anthroposouth_visuals_version_1.ipynb
2025-10-28 08:01:20 +01:00

8.6 KiB

In [ ]:
import sys
import csv
import matplotlib
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
In [ ]:
plt.style.use('default')
In [ ]:
data = pd.read_excel("version_1/input/1. Oil production_1900-2023.xlsx", sheet_name="Latin America (TWh)", header=2)
data.rename(columns={'Unnamed: 0': 'year'}, inplace=True)

Countries of AL - TWh by year

In [ ]:
fig, ax = plt.subplots(figsize = (20,10))

ax.plot(data["year"], data["Bolivia"], label="Bolivia")
ax.plot(data["year"], data["Argentina"], label="Argentina") 
ax.plot(data["year"], data["Colombia"], label="Colombia") 
ax.plot(data["year"], data["Brazil"], label="Brazil") 
ax.plot(data["year"], data["Peru"], label="Peru") 
ax.plot(data["year"], data["Ecuador"], label="Ecuador") 
ax.plot(data["year"], data["Mexico"], label="Mexico") 
ax.plot(data["year"], data["Trinidad & Tobago"], label="Trinidad & Tobago") 
ax.plot(data["year"], data["Venezuela"], label="Venezuela") 

ax.set_xlabel("Year")
ax.set_ylabel("Terawatt hours")
ax.set_title("Latin American oil production in terawatt hours by country (all countries)")

plt.legend(loc="upper left")
plt.savefig("version_1/output/twh_year_all.png")
In [ ]:
fig, ax = plt.subplots(figsize = (20,10))

ax.plot(data["year"], data["Bolivia"], label="Bolivia")
ax.plot(data["year"], data["Peru"], label="Peru") 
ax.plot(data["year"], data["Trinidad & Tobago"], label="Trinidad & Tobago") 

ax.set_xlabel("Year")
ax.set_ylabel("Terawatt hours")
ax.set_title("Latin American oil production in terawatt hours by country (lower tercile)")

plt.legend(loc="upper left")
plt.savefig("version_1/output/twh_year_low.png")
In [ ]:
fig, ax = plt.subplots(figsize = (20,10))

ax.plot(data["year"], data["Argentina"], label="Argentina") 
ax.plot(data["year"], data["Colombia"], label="Colombia") 
ax.plot(data["year"], data["Ecuador"], label="Ecuador") 

ax.set_xlabel("Year")
ax.set_ylabel("Terawatt hours")
ax.set_title("Latin American oil production in terawatt hours by country (median tercile)")

plt.legend(loc="upper left")
plt.savefig("version_1/output/twh_year_middle.png")
In [ ]:
fig, ax = plt.subplots(figsize = (20,10))

ax.plot(data["year"], data["Brazil"], label="Brazil") 
ax.plot(data["year"], data["Mexico"], label="Mexico") 
ax.plot(data["year"], data["Venezuela"], label="Venezuela") 

ax.set_xlabel("Year")
ax.set_ylabel("Terawatt hours")
ax.set_title("Latin American oil production in terawatt hours by country (higher tercile)")

plt.legend(loc="upper left")
plt.savefig("version_1/output/twh_year_high.png")

World versus AL : percentage of TWh by year

In [ ]:
alpercent = data[["year", "Total AL", "World Total"]]
alpercent.rename(columns={"Total AL": "al", "World Total": "world"}, inplace=True)
alpercent["al_percent"] = alpercent["al"] * 100 / alpercent["world"]
alpercent["world_percent"] = 100 - alpercent["al_percent"]
In [ ]:
alpercent["labels"] = alpercent["al_percent"].round(2).astype(str) + "%"
data_total_labels = list(alpercent["labels"])
In [ ]:
fig, ax = plt.subplots(figsize = (8,42))
ax.set_ylim(2024, 1899)
ax.set_xlim(0, 100)

ax.barh(alpercent["year"], alpercent["al_percent"], height=0.5, color="#194d19", label="Latin America")
ax.barh(alpercent["year"], alpercent["world_percent"], left=alpercent["al_percent"], height=0.5, color="#b3e6b3", label="World")

ax.bar_label(ax.containers[0], labels=data_total_labels,
             padding=8, fontsize=9)

ax.bar_label(ax.containers[1], labels=alpercent["world"].round(0).astype(int).astype(str) + " TWh",
             padding=-80, fontsize=9)

ax.set_xlabel("Percentage of TWh production")
ax.set_ylabel("Year")
ax.set_title("Latin America's share of the world oil production")

plt.legend(loc="upper center")
plt.savefig("version_1/output/world_percentage.png")

Energy trade balance

In [ ]:
trade = pd.read_excel("version_1/input/5. Energy trade_1971-2015.xlsx", sheet_name="LA, Energy trade, 1971-2015", header=1)
trade.rename(columns={'Unnamed: 0': 'year', "Unnamed: 1": "trade"}, inplace=True)
trade["percentage"] = trade["trade"].astype(float).abs().round(2)
trade.loc[44, "percentage"] = -6.61
In [ ]:
fig, ax = plt.subplots(figsize = (20,10))
ax.set_ylim(-10, 80)
plt.axhline(y=0, color='black', linestyle='-', lw=0.5)

ax.bar(trade["year"], trade["percentage"], color="#b3e6b3", label="Latin America")
#ax.barh(alpercent["year"], alpercent["world_percent"], left=alpercent["al_percent"], height=0.5, color="#194d19", label="World")

ax.bar_label(ax.containers[0], labels=trade["percentage"].round(0).astype(int).astype(str) + "%",
             padding=5, fontsize=9)

ax.set_xlabel("Year")
ax.set_ylabel("Percentage of energy imported")
ax.set_title("Energy trade in Latin America, as percentage of use, 1971-2015")

plt.legend(loc="upper center")
plt.savefig("version_1/output/trade_balance.png")