Plot Data as a Stack Plot

# sphinx_gallery_thumbnail_number = 2
import matplotlib.pyplot as plt
import pyam

Read in some example data

fname = 'data.csv'
df = pyam.IamDataFrame(fname, encoding='ISO-8859-1')
print(df.head())

Out:

model scenario  region       variable       unit  year      value
0  MESSAGE-GLOBIOM  SSP2-26  R5ASIA  Emissions|CO2  Mt CO2/yr  2005  10488.011
1  MESSAGE-GLOBIOM  SSP2-26  R5ASIA  Emissions|CO2  Mt CO2/yr  2010  13437.424
2  MESSAGE-GLOBIOM  SSP2-26  R5ASIA  Emissions|CO2  Mt CO2/yr  2020  15054.143
3  MESSAGE-GLOBIOM  SSP2-26  R5ASIA  Emissions|CO2  Mt CO2/yr  2030  12528.573
4  MESSAGE-GLOBIOM  SSP2-26  R5ASIA  Emissions|CO2  Mt CO2/yr  2040   9499.867

We generated a simple stacked stack chart as below

data = df.filter(variable='Emissions|CO2|*',
                 level=0,
                 region='World')
data.interpolate(2015)  # some values are missing

fig, ax = plt.subplots(figsize=(10, 10))
data.stack_plot(ax=ax, total=True)
fig.subplots_adjust(right=0.55)
plt.show()
../_images/sphx_glr_plot_stack_001.png

We don’t just have to plot variables, any data or metadata associated with the IamDataFrame can be used.

data = (df
        .filter(variable='Emissions|CO2')
        .filter(region='World', keep=False)
        )
fig, ax = plt.subplots(figsize=(10, 10))
data.stack_plot(ax=ax, stack='region', cmap='tab20', total=True)
plt.show()
../_images/sphx_glr_plot_stack_002.png

Total running time of the script: ( 0 minutes 0.419 seconds)

Gallery generated by Sphinx-Gallery