Presetting

Awesome presets, built-in!

preset keywords

ahlive has these keywords for presetting data:

ahlive keyword

charts

description

trail

scatter

have a line or point follow the original

race

bar, barh

move bars around by ranking

delta

bar, barh

highlight differences between adjacent bars

stacked

bar, barh

pile bars atop rather than side-by-side

morph

line, scatter, bar, barh

plot all states simultaneously

morph_trail

line, scatter

plot all states simultaneously plus trail

morph_stacked

bar, barh

plot all states simultaneously plus stacked

rotate

pcolormesh, contourf, contour

show data on a revolving globe

scan_x

pcolormesh, contourf, contour

replace old data with new from left to right

scan_y

pcolormesh, contourf, contour

replace old data with new from top to bottom

trail

trail allows scatter charts to leave behind footprints.

[1]:
import ahlive as ah
ah.Array([0, 1, 2], [3, 4, 5], preset='trail').render()
[########################################] | 100% Completed |  6.1s
gifsicle: warning: trivial adaptive palette (only 211 colors in source)
[1]:

trail can be configured to expire in number of base states and only show a trailing line.

[2]:
import ahlive as ah
arr = ah.Array([0, 1, 2], [0, 1, 0], chart='scatter', preset='trail')
arr.config('preset', chart='line', expire=1).render()
[########################################] | 100% Completed |  6.0s
[2]:

race

race will yield bar chart races as long as there is more than one item overlaid. It’s also possible to customize bar_label and ascending.

[3]:
import ahlive as ah
import pandas as pd
x = ['a', 'a', 'b', 'b']
y =  [4, 5, 3, 8]
df = pd.DataFrame({'x': x, 'y': y})
ah.DataFrame(
    df, 'x', 'y', label='x', inline_labels='y',
    chart='barh', preset='race'
).config(
    'preset', bar_label=False, ascending=True
).render()
[########################################] | 100% Completed |  4.1s
[3]:

delta

delta will highlight the differences in values for bar charts.

[4]:
import ahlive as ah
import pandas as pd
x = ['a', 'a', 'b', 'b']
y =  [4, 5, 3, 8]
df = pd.DataFrame({'x': x, 'y': y})
ah.DataFrame(
    df, 'x', 'y', label='x', inline_labels='y',
    chart='bar', preset='delta'
).render()
[########################################] | 100% Completed |  4.7s
[4]:

stacked

Create stacked bar charts instead of the default side by side.

[5]:
import ahlive as ah

x = [0, 0]
y1 = [1, 0]
y2 = [2, 0]

(ah.Array(x, y1, label="A", preset="stacked", chart="bar", revert="boomerang") *
 ah.Array(x, y2, label="B", preset="stacked", chart="bar", ylims="fixed")
).render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/main/lib/python3.9/site-packages/ahlive-0.0.3.post178+dirty-py3.9.egg/ahlive/data.py:408: UserWarning: Multiple items found, you may want to use the 'morph' preset
[########################################] | 100% Completed |  5.4s
[5]:

morph

The initial states are batched together and each item gets morphed into a new state, grouped by group as the new items.

[6]:
import ahlive as ah

x = [0, 1, 2, 3]
y1 = [4, 5, 6, 7]
y2 = [2, 10, 15, 20]

(
    ah.Array(x, y1, group="A") *  # item 1, state 1
    ah.Array(x, y2, group="A") *  # item 1, state 2
    ah.Array(x, y2, group="B") *  # item 2, state 1
    ah.Array(x, y1, group="B", chart="line", preset="morph", fps=30, revert="boomerang")  # item 2, state 2
).render()
[########################################] | 100% Completed |  7.4s
gifsicle: warning: trivial adaptive palette (only 256 colors in source)
[6]:

morph_trail

Same as morph with a footprint.

[7]:
import ahlive as ah

x = [0, 1, 2]
y1 = [0, 36, 0]
y2 = [0, 72, 0]
y3 = [0, 144, 0]

(
    ah.Array(x, y1) *
    ah.Array(x, y2) *
    ah.Array(x, y3, preset="morph_trail", chart="line", color="red")
).config(
    "preset", color="gray"
).render()
[########################################] | 100% Completed |  6.3s
[7]:

morph_stacked

Same as morph, but for bar and barh charts: stacking separate groups.

[8]:
import ahlive as ah

x = [0, 1]
y1 = [0, 0.8]
y2 = [1, 0.2]

(
    ah.Array(x, y1, group="A", preset="morph_stacked", xlims="fixed",
             fps=30, revert="boomerang", chart="barh") *  # item 1, state 1
    ah.Array(x, y2, group="A", chart="barh") *  # item 1, state 2
    ah.Array(x, y2, group="B", chart="barh") *  # item 2, state 1
    ah.Array(x, y1, group="B", chart="barh")  # item 2, state 2
).render()
[########################################] | 100% Completed |  5.5s
[8]:

rotate

rotate will yie ld a rotating globe for gridded charts. Geostationary views of the world can be achieved through worldwide=True, and the start and end of the central longitudes can be specified as a tuple in central_lon.

[9]:
import xarray as xr
import ahlive as ah
ds = xr.tutorial.open_dataset('air_temperature').isel(time=slice(0, 8))
ah.Dataset(
    ds, 'lon', 'lat', 'air', crs='platecarree', preset='rotate',
    central_lon=(-90, -110), worldwide=True
).render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/main/lib/python3.9/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
[########################################] | 100% Completed | 20.6s
[9]: