506 lines
15 KiB
Text
506 lines
15 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c09834e2-1f4d-4b97-b5bb-50f8940bfcab",
|
|
"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": "markdown",
|
|
"id": "67f7914b-a7a7-4d96-b92f-9cb6c788f063",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 1 - Oil production\n",
|
|
"\n",
|
|
"Relative oil production per country between 1900 and 2023"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6f8dcf94-577f-4b44-a658-1e9fd07469d4",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# load data, set index, and workout total production in given unit\n",
|
|
"oil = pd.read_csv(\"version_2/input/oilproductionrelative_v2.csv\")\n",
|
|
"oil.set_index(\"Year\", inplace=True)\n",
|
|
"oil['Total'] = oil.sum(axis=1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "19d81163-1d42-407b-bf34-2fe194593285",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# relative percentage of production into \"country_percent\" columns\n",
|
|
"for column in oil:\n",
|
|
" oil[column + \"_percent\"] = oil[column] / oil.Total"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "49ba427d-7d99-4b11-a121-1bfe1c9aec42",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# grey palette for black and white printing\n",
|
|
"sns.set_palette(\"Greys\")\n",
|
|
"\n",
|
|
"# decent size and light grey background\n",
|
|
"fig, ax = plt.subplots(figsize = (17,8))\n",
|
|
"ax.set_facecolor('#fdfdfd')\n",
|
|
"\n",
|
|
"# actual plot\n",
|
|
"ax.stackplot(\n",
|
|
" oil.index,\n",
|
|
" oil.Argentina_percent,\n",
|
|
" oil.Brazil_percent,\n",
|
|
" oil.Colombia_percent,\n",
|
|
" oil.Ecuador_percent,\n",
|
|
" oil.Mexico_percent,\n",
|
|
" oil.Venezuela_percent,\n",
|
|
" oil.Others_percent\n",
|
|
")\n",
|
|
"\n",
|
|
"# minimalistic x axis without precise ticks\n",
|
|
"plt.xticks(np.arange(1900, 2023, 10))\n",
|
|
"ax.get_yaxis().set_ticks([])\n",
|
|
"ax.tick_params(length=4, color=\"white\")\n",
|
|
"#plt.xticks(ha='left')\n",
|
|
"#ax.tick_params(labelrotation=-35)\n",
|
|
"\n",
|
|
"# no border, clean layout, no non-sense\n",
|
|
"ax.spines['top'].set_visible(False)\n",
|
|
"ax.spines['right'].set_visible(False)\n",
|
|
"ax.spines['bottom'].set_visible(False)\n",
|
|
"ax.spines['left'].set_visible(False)\n",
|
|
"ax.set_ymargin(0.005)\n",
|
|
"ax.set_xmargin(0)\n",
|
|
"\n",
|
|
"# legend placement is manual (and tricky)\n",
|
|
"labels_legend = [\n",
|
|
" 'Argentina',\n",
|
|
" 'Brazil',\n",
|
|
" 'Colombia',\n",
|
|
" 'Ecuador',\n",
|
|
" 'Mexico',\n",
|
|
" 'Venezuela',\n",
|
|
" 'Others']\n",
|
|
"ax.legend(labels=labels_legend, loc='right', bbox_to_anchor=(0.558, 0.5, 0.545, 0.77), edgecolor=\"white\", reverse=True)\n",
|
|
"\n",
|
|
"# output to file\n",
|
|
"plt.savefig(\"version_2/output/1_oil.png\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6d1ead40-e7ae-4dc3-826e-3c437108080d",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 2 - Selected\n",
|
|
"\n",
|
|
"Subset of 3 countries with raw amounts\n",
|
|
"\n",
|
|
"__Important__: match the colors to other graphics"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "afdca3f2-4605-4147-a0bb-f7a67af65341",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# load data, set index\n",
|
|
"selected = pd.read_csv(\"version_2/input/1-laselected.csv\")\n",
|
|
"selected.set_index(\"Year\", inplace=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f051778e-eed5-4288-8027-e62b1c68598d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# custom palette to match country colors to first plot\n",
|
|
"palette_selected = [\"#d1d1d1\", \"#5c5c5c\", \"#2b2b2b\"]\n",
|
|
"sns.set_palette(sns.color_palette(palette_selected))\n",
|
|
"\n",
|
|
"# all plots with same lightest grey background\n",
|
|
"fig, ax = plt.subplots(figsize = (17,8))\n",
|
|
"ax.set_facecolor('#fdfdfd')\n",
|
|
"\n",
|
|
"# actual plot\n",
|
|
"ax.stackplot(\n",
|
|
" selected.index,\n",
|
|
" selected.Brazil,\n",
|
|
" selected.Mexico,\n",
|
|
" selected.Venezuela\n",
|
|
")\n",
|
|
"\n",
|
|
"# Raw numbers need a Y axis scale and lines\n",
|
|
"plt.xticks(np.arange(1900, 2021, 10))\n",
|
|
"plt.yticks(np.arange(1000, 6000, 1000))\n",
|
|
"ax.tick_params(length=4, color=\"white\")\n",
|
|
"#plt.xticks(ha='left')\n",
|
|
"ax.grid(axis=\"y\")\n",
|
|
"\n",
|
|
"# no border, clean layout, no non-sense\n",
|
|
"ax.spines['top'].set_visible(False)\n",
|
|
"ax.spines['right'].set_visible(False)\n",
|
|
"ax.spines['bottom'].set_visible(False)\n",
|
|
"ax.spines['left'].set_visible(False)\n",
|
|
"ax.set_ymargin(0.005)\n",
|
|
"ax.set_xmargin(0)\n",
|
|
"\n",
|
|
"# legend placement is manual (and tricky)\n",
|
|
"labels_legend = [\n",
|
|
" 'Brazil',\n",
|
|
" 'Mexico',\n",
|
|
" 'Venezuela',\n",
|
|
"]\n",
|
|
"ax.legend(labels=labels_legend, loc='right', bbox_to_anchor=(0.558, 0.5, 0.544, 0.91), edgecolor=\"white\", reverse=True)\n",
|
|
"\n",
|
|
"# output to file\n",
|
|
"plt.savefig(\"version_2/output/2_selected.png\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d950448c-503b-4c77-a48a-a4ffcb686d14",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 3 - Raffinage\n",
|
|
"Raw data of oil refinment by country of shorter period of time (1940-2023)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "863148f6-5ad4-456a-81ac-ccbbc347a9da",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# load data, set index\n",
|
|
"raffinage = pd.read_csv(\"version_2/input/2-refining.csv\")\n",
|
|
"raffinage.set_index(\"Year\", inplace=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "44fd6c05-2fd9-4a71-8ff3-28e35eb2a4fb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Same palette as first (oil) plot but Ecuador is now Peru\n",
|
|
"sns.set_palette(\"Greys\")\n",
|
|
"\n",
|
|
"# same size and background color\n",
|
|
"fig, ax = plt.subplots(figsize = (17,8))\n",
|
|
"ax.set_facecolor('#fdfdfd')\n",
|
|
"\n",
|
|
"# actual plot\n",
|
|
"ax.stackplot(\n",
|
|
" raffinage.index,\n",
|
|
" raffinage.Argentina,\n",
|
|
" raffinage.Brazil,\n",
|
|
" raffinage.Colombia,\n",
|
|
" raffinage.Peru,\n",
|
|
" raffinage.Mexico,\n",
|
|
" raffinage.Venezuela\n",
|
|
")\n",
|
|
"\n",
|
|
"# Raw numbers need a Y axis scale and lines\n",
|
|
"plt.xticks(np.arange(1940, 2023, 10))\n",
|
|
"plt.yticks(np.arange(1000, 7000, 1000))\n",
|
|
"ax.tick_params(length=4, color=\"white\")\n",
|
|
"#plt.xticks(ha='left')\n",
|
|
"ax.grid(axis=\"y\")\n",
|
|
"\n",
|
|
"# same minimalist look\n",
|
|
"ax.spines['top'].set_visible(False)\n",
|
|
"ax.spines['right'].set_visible(False)\n",
|
|
"ax.spines['bottom'].set_visible(False)\n",
|
|
"ax.spines['left'].set_visible(False)\n",
|
|
"ax.set_ymargin(0.005)\n",
|
|
"ax.set_xmargin(0)\n",
|
|
"\n",
|
|
"# legend\n",
|
|
"labels_legend = [\n",
|
|
" 'Argentina',\n",
|
|
" 'Brazil',\n",
|
|
" 'Colombia',\n",
|
|
" 'Peru',\n",
|
|
" 'Mexico',\n",
|
|
" 'Venezuela',\n",
|
|
"]\n",
|
|
"ax.legend(labels=labels_legend, loc='right', bbox_to_anchor=(0.558, 0.5, 0.545, 0.80), edgecolor=\"white\", reverse=True)\n",
|
|
"\n",
|
|
"# output to file\n",
|
|
"plt.savefig(\"version_2/output/3_raffinage.png\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0d8dd45e-5b6d-4e1d-a283-10e05265b599",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 4 - Energy mix\n",
|
|
"General proportion of energy production source from 1800 to 2000"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "85b04a56-62a4-46db-9b92-499b09177afb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# load data, set index, and workout total production in given unit\n",
|
|
"mix = pd.read_csv(\"version_2/input/3-energymix.csv\")\n",
|
|
"mix.set_index(\"Year\", inplace=True)\n",
|
|
"mix['Total'] = mix.sum(axis=1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d05090cd-2c40-4920-88df-97b8d2aec519",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# workout percentages in their columns\n",
|
|
"for column in mix:\n",
|
|
" mix[column + \"_percent\"] = mix[column] / mix.Total"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "0a446974-6469-44ac-b406-88ab0247bbd1",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# custom palette to prevent dark grey \"biomass\" to empty printer black ink\n",
|
|
"paletto = [\n",
|
|
" \"#ededed\",\n",
|
|
" \"#d1d1d1\",\n",
|
|
" \"#adadad\",\n",
|
|
" \"#828282\",\n",
|
|
" \"#5c5c5c\"\n",
|
|
"]\n",
|
|
"\n",
|
|
"# same settings as before\n",
|
|
"fig, ax = plt.subplots(figsize = (17,8))\n",
|
|
"ax.set_facecolor('#fdfdfd')\n",
|
|
"\n",
|
|
"# actual plot\n",
|
|
"ax.stackplot(\n",
|
|
" mix.index,\n",
|
|
" mix.Coal_percent,\n",
|
|
" mix.Oil_percent,\n",
|
|
" mix[\"Natural gas_percent\"],\n",
|
|
" mix.Electricity_percent,\n",
|
|
" mix.Biomass_percent,\n",
|
|
" colors = paletto[::-1]\n",
|
|
")\n",
|
|
"\n",
|
|
"# this is ugly, don't look\n",
|
|
"ax.get_yaxis().set_ticks([])\n",
|
|
"ax.get_xaxis().set_ticks([1800, 1850, 1900, 1950, 1995])\n",
|
|
"x_labels = [\"1800\", \"1850\", \"1900\", \"1950\", \"2000\"]\n",
|
|
"ax.set_xticklabels(x_labels)\n",
|
|
"ax.tick_params(length=4, color=\"white\")\n",
|
|
"#plt.xticks(ha='left')\n",
|
|
"\n",
|
|
"# same clean look\n",
|
|
"ax.spines['top'].set_visible(False)\n",
|
|
"ax.spines['right'].set_visible(False)\n",
|
|
"ax.spines['bottom'].set_visible(False)\n",
|
|
"ax.spines['left'].set_visible(False)\n",
|
|
"ax.set_ymargin(0.005)\n",
|
|
"ax.set_xmargin(0)\n",
|
|
"\n",
|
|
"# legend\n",
|
|
"labels_legend = [\n",
|
|
" 'Coal',\n",
|
|
" 'Oil',\n",
|
|
" 'Natural gas',\n",
|
|
" 'Electricity',\n",
|
|
" 'Biomass'\n",
|
|
"]\n",
|
|
"ax.legend(labels=labels_legend, loc='right', bbox_to_anchor=(0.558, 0.5, 0.55, 0.832), edgecolor=\"white\", reverse=True)\n",
|
|
"\n",
|
|
"# output to file\n",
|
|
"plt.savefig(\"version_2/output/4_mix.png\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4cb24807-ee27-4f07-a850-a3d86b8ac20f",
|
|
"metadata": {},
|
|
"source": [
|
|
"__Note regarding x axis labels placement__\n",
|
|
"\n",
|
|
"In most of the plots (oil, raffinage, selected), labels on the x axis are \"anchored left of their ticks\". It means that they are shifted slightly to the right relative to the actual date. Their respective individual tick, placed on the x axis at the precise date, are aligned with the tip of the first character of the label, not the middle, as is the case with the above plot (mix).\n",
|
|
"This was done to prevent the first and last label to be visualy misaligned with the frame of the plot. The first label would be halfway out of the frame, and the last (2020) would be entirely inside the frame, as the source data have yearly datapoints until 2023.\n",
|
|
"Label have been shifted to visualy mark this imprecision. Conveying a sense of temporal blur, it underlines the function of these visual representations: these are not precise analytical tools, but allow the reader to perceive historical trends in the data."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6be6896b-fd0a-4ad9-8b39-d89dfbacec40",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 5 - Energy balance"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "8b157268-bb09-4cd9-98b1-d0f91a790430",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# load data, set index, and workout total production in given unit\n",
|
|
"balance = pd.read_csv(\"version_2/input/5-energybalance.csv\")\n",
|
|
"balance.set_index(\"Year\", inplace=True)\n",
|
|
"balance['Total'] = balance.sum(axis=1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4ae87e36-3268-4c74-acb6-8abd27cc9724",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# workout percentages in their columns\n",
|
|
"for column in balance:\n",
|
|
" balance[column + \"_percent\"] = balance[column] / balance.Total"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a825f3fe-ec3d-4ec4-b227-e38cd027f1c2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# custom palette matches the biomass one\n",
|
|
"paletto = [\n",
|
|
" \"#ededed\",\n",
|
|
" \"#d1d1d1\",\n",
|
|
" \"#adadad\",\n",
|
|
" \"#828282\",\n",
|
|
" \"#5c5c5c\"\n",
|
|
"]\n",
|
|
"\n",
|
|
"# same settings as before\n",
|
|
"fig, ax = plt.subplots(figsize = (17,8))\n",
|
|
"ax.set_facecolor('#fdfdfd')\n",
|
|
"\n",
|
|
"# actual plot\n",
|
|
"ax.stackplot(\n",
|
|
" balance.index,\n",
|
|
" balance.Renewables_percent,\n",
|
|
" balance[\"Nuclear consumption - TWh_percent\"],\n",
|
|
" balance[\"Gas consumption - TWh_percent\"],\n",
|
|
" balance[\"Coal consumption - TWh_percent\"],\n",
|
|
" balance[\"Oil consumption - TWh_percent\"],\n",
|
|
" colors = paletto[::-1]\n",
|
|
")\n",
|
|
"\n",
|
|
"# custom x axis labels because data starts earlier\n",
|
|
"start = np.array([1965])\n",
|
|
"middle = np.arange(1970, 2019, 10)\n",
|
|
"end = np.array([2020])\n",
|
|
"ticks_array = np.concatenate((start, middle, end), axis=0)\n",
|
|
"plt.xticks(ticks_array)\n",
|
|
"ax.get_yaxis().set_ticks([])\n",
|
|
"ax.tick_params(length=4, color=\"white\")\n",
|
|
"#ax.tick_params(rotation=35)\n",
|
|
"#plt.xticks(ha='left')\n",
|
|
"\n",
|
|
"# same clean look\n",
|
|
"ax.spines['top'].set_visible(False)\n",
|
|
"ax.spines['right'].set_visible(False)\n",
|
|
"ax.spines['bottom'].set_visible(False)\n",
|
|
"ax.spines['left'].set_visible(False)\n",
|
|
"ax.set_ymargin(0.005)\n",
|
|
"ax.set_xmargin(0)\n",
|
|
"\n",
|
|
"# legend\n",
|
|
"labels_legend = [\n",
|
|
" 'Renewables',\n",
|
|
" 'Nuclear',\n",
|
|
" 'Gas',\n",
|
|
" 'Coal',\n",
|
|
" 'Oil',\n",
|
|
"]\n",
|
|
"ax.legend(labels=labels_legend, loc='right', bbox_to_anchor=(0.558, 0.5, 0.55, 0.832), edgecolor=\"white\", reverse=True)\n",
|
|
"\n",
|
|
"# output to file\n",
|
|
"plt.savefig(\"version_2/output/5_balance.png\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "40b58100-f567-4468-826a-c7826a8f4e17",
|
|
"metadata": {},
|
|
"source": [
|
|
"__Note regarding input data pre-processing__\n",
|
|
"\n",
|
|
"All datasets have been manually collected, curated, corrected for formatting error, converted to csv with appropriate headers and verified."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "653d050e-1845-40ca-be40-25d488445036",
|
|
"metadata": {},
|
|
"source": [
|
|
"__Note 2025-11-05__\n",
|
|
"\n",
|
|
"The \"ha\" alignment to the right that contained the x-axis years into the frame of the plots has been commented out because it conflicted with an argument made in the text about coal starting in 1890, and a plot showing coal starting around 1860."
|
|
]
|
|
}
|
|
],
|
|
"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
|
|
}
|