%matplotlib inline
import math
import matplotlib.pyplot as plt
plt.rcParams.update({'mathtext.default': 'regular'})
plt.style.use("ggplot")
from pandas_datapackage_reader import read_datapackage
Let's load the global fossil fuel and cement production emissions data from the Global Carbon Budget. It has been pre-processed for easy reading in as a data package.
ffc = read_datapackage("https://github.com/openclimatedata/global-carbon-budget",
"fossil-fuel-cement")
ffc.head()
Value | Source | ||
---|---|---|---|
Year | Category | ||
1959 | Total | 2453 | CDIAC |
1960 | Total | 2568 | CDIAC |
1961 | Total | 2579 | CDIAC |
1962 | Total | 2685 | CDIAC |
1963 | Total | 2832 | CDIAC |
Turn it into a wide table, with one variable per column.
ffc = ffc.drop("Source", axis=1).reset_index().pivot(columns="Category", values="Value", index="Year")
Conversion to Gt and to tonnes CO$_2$ instead of tonnes C.
ffc_Gt_CO2 = ffc[["Total", "Coal", "Oil", "Gas", "Cement", "Flaring"]] * 3.664 / 1000
ffc_Gt_CO2[["Coal", "Oil", "Gas", "Cement", "Flaring"]].plot.area(stacked=True)
plt.title("Global Emissions from Fossil Fuel and Cement Production (Data: Global Carbon Budget)")
plt.ylabel("Gt CO$_2$");
subcategories = ffc_Gt_CO2[["Coal", "Oil", "Gas", "Cement", "Flaring"]]
ymax = math.ceil(subcategories.max(axis=1).max())
axes = subcategories.plot.area(subplots=True, layout=(3,2), ylim=(0, ymax))
plt.suptitle("Global Emissions from Fossil Fuel and Cement Production in Gt CO$_2$ (Data: Global Carbon Budget)");
Per-Capita emissions are included in the dataset. We convert to t CO$_2$ per person per year.
per_capita_CO2 = read_datapackage("https://github.com/openclimatedata/global-carbon-budget",
"fossil-fuel-cement-per-capita").drop("Source", axis=1) * 3.664
per_capita_CO2.plot()
plt.title("Per-Capita Emissions in t CO$_2$ per person per year (Source: Global Carbon Budget)");
Let's pull in a population data package to have a look at the population growth.
population = read_datapackage("https://github.com/datasets/population")
world_population = population[population["Country Name"] == "World"][["Year", "Value"]].set_index("Year")
world_population = world_population.Value
(world_population / 10**9).plot()
plt.legend("")
plt.title("World population in billion (Source: World Bank)");
ffc_t_CO2 = ffc_Gt_CO2 * 10**9
Re-creating the above plot of per-capita emissions by doing the calculation with the new dataset and plotting them together shows minor differences due to using different population data.
ax = ffc_t_CO2.Total.loc[1960:].divide(world_population).plot()
per_capita_CO2.plot(ax=ax)
plt.legend(["Global Carbon Budget", "Global Carbon Budget/World Bank"],
loc="upper left")
plt.title("Per-Capita Emissions in t CO$_2$ per person per year (Source: Global Carbon Budget/World Bank)");
Let's look at what the per-capita emissions consist of:
per_capita_categories = ffc_t_CO2[["Coal", "Oil", "Gas", "Cement"]].loc[1960:].divide(
world_population, axis=0)
per_capita_categories.plot(subplots=True, layout=(2,2), ylim=(0, 2.3))
plt.suptitle("Per-Capita Emissions in t CO$_2$ per person per year (Source: Global Carbon Budget/World Bank)");