Boxplot charts

# sphinx_gallery_thumbnail_number = 2

Read in tutorial data and show a summary

This gallery uses the scenario data from the first-steps tutorial.

If you haven’t cloned the pyam GitHub repository to your machine, you can download the file from

Make sure to place the data file in the same folder as this script/notebook.

import matplotlib.pyplot as plt
import pyam

df = pyam.IamDataFrame("tutorial_data.csv")
<class 'pyam.core.IamDataFrame'>
 * model    : AIM/CGE 2.1, GENeSYS-MOD 1.0, ... WITCH-GLOBIOM 4.4 (8)
 * scenario : 1.0, CD-LINKS_INDCi, CD-LINKS_NPi, ... Faster Transition Scenario (8)
Timeseries data coordinates:
   region   : R5ASIA, R5LAM, R5MAF, R5OECD90+EU, R5REF, R5ROWO, World (7)
   variable : ... (6)
   unit     : EJ/yr, Mt CO2/yr, °C (3)
   year     : 2010, 2020, 2030, 2040, 2050, 2060, 2070, 2080, ... 2100 (10)
Meta indicators:
   exclude (bool) False (1)

A boxplot of CO emissions

We generate a simple boxplot of CO2 emissions across one scenario implemented by a range of models.

data = df.filter(
    scenario="CD-LINKS_NPi2020_1000", variable="Emissions|CO2", region="World"
plot boxplot
No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.

A grouped boxplot

We can add sub-groupings of the data using the keyword argument by.

data = df.filter(
    year=[2010, 2020, 2030, 2050, 2100],
).filter(region="World", keep=False)"year", by="region", legend=True)

# We can use matplotlib arguments to make the figure more appealing.
plot boxplot

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

Gallery generated by Sphinx-Gallery