diff --git a/anthroposouth_visuals_version_2.ipynb b/anthroposouth_visuals_version_2.ipynb index eed30e0..5aadfb0 100644 --- a/anthroposouth_visuals_version_2.ipynb +++ b/anthroposouth_visuals_version_2.ipynb @@ -127,7 +127,7 @@ "outputs": [], "source": [ "# load data, set index\n", - "selected = pd.read_csv(\"final_sources/1-laselected.csv\")\n", + "selected = pd.read_csv(\"version_2/input/1-laselected.csv\")\n", "selected.set_index(\"Year\", inplace=True)" ] }, @@ -363,13 +363,112 @@ "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": "eac58e10-4305-4175-b01c-3744a319e014", + "id": "8b157268-bb09-4cd9-98b1-d0f91a790430", "metadata": {}, "outputs": [], - "source": [] + "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", + " '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/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." + ] } ], "metadata": {