Quick Start#

It’s easy as 1 - 2 - 3!

1 - import package#

The standard is to abbreviate ahlive as ah.

[1]:
import ahlive as ah

2 - load data#

Here, CO2 concentrations data is fetched.

[2]:
df = ah.open_dataset("annual_co2", names=["year", "co2", "uncertainty"], verbose=True)
display(df)
ANNUAL CO2

Source: NOAA ESRL
https://www.esrl.noaa.gov/

Description: The carbon dioxide data on Mauna Loa constitute the longest record of direct measurements of CO2 in the atmosphere. They were started by C. David Keeling of the Scripps Institution of Oceanography in March of 1958 at a facility of the National Oceanic and Atmospheric Administration [Keeling, 1976]. NOAA started its own CO2 measurements in May of 1974, and they have run in parallel with those made by Scripps since then [Thoning, 1989].

Data: https://www.esrl.noaa.gov/gmd/webdata/ccgg/trends/co2/co2_annmean_mlo.txt

year co2 uncertainty
0 1959 315.98 0.12
1 1960 316.91 0.12
2 1961 317.64 0.12
3 1962 318.45 0.12
4 1963 318.99 0.12
... ... ... ...
58 2017 406.76 0.12
59 2018 408.72 0.12
60 2019 411.66 0.12
61 2020 414.24 0.12
62 2021 416.45 0.12

63 rows × 3 columns

3 - generate animation#

Simply input the dataframe, df and map the dataframe’s column names to the plot’s axes, xs and ys.

[3]:
ah.DataFrame(
    df,
    xs="year",
    ys="co2",
).render()
[3]:

add refinements#

In just three steps, an animation was output, but don’t stop there! Take advantage of the features supported in ahlive, conveniently accessible by keywords!

[4]:
import ahlive as ah

df, meta = ah.open_dataset(
    "annual_co2",
    names=["year", "co2", "uncertainty"],
    index_col="year",
    return_meta=True
)
df_cummax = df.cummax()

ah.DataFrame(
    df,
    # map columns to axes
    xs="year",
    ys="co2",

    # add dynamic labels
    inline_labels="co2",
    state_labels="year",

    # add static labels
    title=meta["label"].title(),
    ylabel="CO2 Concentrations [PPM]",
    note=meta["base_url"],
    caption=meta["description"].split("\n")[0].title(),

    # adjust dynamic limits
    ylim1s="fixed",
    xlim1s="explore_5",

    # adjust figure
    figsize=(13, 7),
    ymargins=0.1
).reference(
    y0s=df_cummax["co2"],
    inline_labels=df_cummax["co2"],
    inline_locs=1000
).remark(
    "Intergovernmental Panel on Climate Change (IPCC) is established",
    xs=1988
).remark(
    "CO2 levels surpasses 400 PPM for the first time in recorded history",
    xs=2016  # based off Scripp's records
).config(**{
    "ref_inline": dict(prefix="Record max of ", suffix=" PPM", ha="center"),
    "inline": dict(suffix=" PPM"),
    "caption": dict(width=120)
}).render()
[4]: