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, errorbar, area

plot all states simultaneously

morph_trail

line, scatter, errorbar, area

plot all states simultaneously plus trail

morph_stacked

bar, barh

plot all states simultaneously plus stacked

rotate

line, scatter, errorbar, area, pcolormesh, contourf, contour, hexbin, quiver, streamplot

show data on a revolving globe

scan_x

pcolormesh, contourf, contour, hexbin, quiver, streamplot

replace old data with new from left to right

scan_y

pcolormesh, contourf, contour, hexbin, quiver, streamplot

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], color="red", preset='trail').render()
gifsicle: warning: trivial adaptive palette (only 210 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()
[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, 6]
df = pd.DataFrame({'x': x, 'y': y})
ah.DataFrame(
    df, 'x', 'y', label='x', inline_labels='y',
    chart='bar', preset='race'
).config(
    'preset', bar_label=False, ascending=True
).render()
[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='barh', preset='delta'
).render()
[4]:

stacked

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

[5]:
import ahlive as ah

x = ["X", "X"]
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=(0, 3))
).render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/ahlive-1.0.0.post4+dirty-py3.9.egg/ahlive/data.py:426: UserWarning: Multiple items found, you may want to use the 'morph' preset
[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()
[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, group="a") *
    ah.Array(x, y3, group="a") *
    ah.Array(x, y2, group="b") *
    ah.Array(x, y1, group="b", preset="morph_trail", chart="line", revert="boomerang")
).config(
    "preset", color="gray"
).render()
[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") *  # 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", preset="morph_stacked", ylims="fixed",
             fps=30, revert="boomerang", chart="barh")  # item 2, state 2
).render()
[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/latest/lib/python3.9/site-packages/cartopy/crs.py:825: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  if len(multi_line_string) > 1:
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:836: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  line_strings = list(multi_line_string)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:836: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  line_strings = list(multi_line_string)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:877: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for line in multi_line_string:
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:944: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  if len(p_mline) > 0:
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:982: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  line_strings.extend(multi_line_string)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:825: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  if len(multi_line_string) > 1:
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:982: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  line_strings.extend(multi_line_string)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:836: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  line_strings = list(multi_line_string)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/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)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:836: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  line_strings = list(multi_line_string)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:877: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for line in multi_line_string:
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:944: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  if len(p_mline) > 0:
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:982: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  line_strings.extend(multi_line_string)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.9/site-packages/cartopy/crs.py:982: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  line_strings.extend(multi_line_string)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/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)
[9]: