Merging#

ahlive allows data to be combined into a single figure to let the animations run simultaneously.

merging functions#

ahlive has these functions for merging data:

ahlive function

method

operator

description

ah.overlay

overlay

*

stack plots over one another into a single subplot

ah.cascade

cascade

-

like overlay, but animates the data serially, one after another

ah.stagger

stagger

**

like overlay, but animates the data in a staggered fashion, step by step

ah.slide

slide

//

like overlay, but delays the latter datasets by a single frame

ah.layout

layout

+ /

arrange plots horizontally or vertically as multiple subplots

ah.merge

n/a

n/a

a generic method for all merges by specifying join

overlay#

To overlay, simply multiply the objects.

This results in an ah.Data object that contains multiple items within the wrapped xr.Dataset.

[1]:
import ahlive as ah
arr1 = ah.Array([0, 1, 2], [4, 5, 4], label='Array One', chart='line')
arr2 = ah.Array([0, 1, 2], [3, 5, 6], label='Array Two', chart='line')
# equivalently arr1.overlay(arr2) or ah.overlay([arr1, arr2])
overlay = arr1 * arr2
print(overlay)
overlay.render()
<ahlive.Data>
Subplot:         (1, 1)
Dimensions:      (item: 2, state: 3)
Data variables:
    x        (item, state) float64 0.0 1.0 2.0 0.0 1.0 2.0
    y        (item, state) float64 4.0 5.0 4.0 3.0 5.0 6.0
    chart    (item) <U4 'line' 'line'
    label    (item, state) object 'Array One' 'Array One' ... 'Array Two'
    group    (item) <U1 '' ''
Attributes (0/49):


[1]:

cascade#

To cascade, simply subtract the objects.

Similar to overlay, this results in an ah.Data object that contains multiple items within the wrapped xr.Dataset, but the difference is that the first ah.Data object’s animation concludes before the second ah.Data object is starts.

[2]:
import ahlive as ah
arr1 = ah.Array([0, 1, 2], [0, 5, 4], label='Array One', chart='line')
arr2 = ah.Array([0, 1, 2], [3, 5, 6], label='Array Two', chart='line')
# equivalently arr1.cascade(arr2) or ah.cascade([arr1, arr2])
cascade = arr1 - arr2
print(cascade)
cascade.render()
<ahlive.Data>
Subplot:         (1, 1)
Dimensions:      (item: 2, state: 6)
Data variables:
    x        (item, state) float64 0.0 1.0 2.0 2.0 2.0 ... nan nan 0.0 1.0 2.0
    y        (item, state) float64 0.0 5.0 4.0 4.0 4.0 ... nan nan 3.0 5.0 6.0
    chart    (item) object 'line' 'line'
    label    (item, state) object 'Array One' 'Array One' ... 'Array Two'
    group    (item) object '' ''
Attributes (0/49):


gifsicle: warning: trivial adaptive palette (only 201 colors in source)
[2]:

stagger#

To stagger, use the exponent symbol on the objects.

Similar to overlay and cascade, this results in an ah.Data object that contains additional items and states within the wrapped xr.Dataset, but the difference is that the first ah.Data and the second ah.Data objects take turns animating.

[3]:
import ahlive as ah
arr1 = ah.Array([0, 1, 2], [0, 5, 4], label='Array One', chart='line')
arr2 = ah.Array([0, 1, 2], [3, 5, 6], label='Array Two', chart='line')
# equivalently arr1.stagger(arr2) or ah.stagger([arr1, arr2])
stagger = arr1 ** arr2
print(stagger)
stagger.render()
<ahlive.Data>
Subplot:         (1, 1)
Dimensions:      (item: 2, state: 6)
Data variables:
    x        (item, state) float64 0.0 1.0 1.0 2.0 2.0 ... 0.0 1.0 1.0 2.0 2.0
    y        (item, state) float64 0.0 5.0 5.0 4.0 4.0 ... 3.0 5.0 5.0 6.0 6.0
    chart    (item) object 'line' 'line'
    label    (item, state) object 'Array One' 'Array One' ... 'Array Two'
    group    (item) object '' ''
Attributes (0/49):


[3]:

slide#

To slide, use the floor division symbol on the objects.

Similar to overlay, cascade, and stagger, this results in an ah.Data object that contains additional items and states within the wrapped xr.Dataset, but the latter ah.Data objects’ frames are offset by one and animated simultaneously.

[4]:
import ahlive as ah
arr1 = ah.Array([0, 1, 2], [0, 5, 4], label='Array One', chart='line')
arr2 = ah.Array([0, 1, 2], [3, 5, 6], label='Array Two', chart='line')
# equivalently arr1.slide(arr2) or ah.slide([arr1, arr2])
slide = arr1 // arr2
print(slide)
slide.render()
<ahlive.Data>
Subplot:         (1, 1)
Dimensions:      (item: 2, state: 4)
Data variables:
    x        (item, state) float64 0.0 1.0 2.0 2.0 0.0 0.0 1.0 2.0
    y        (item, state) float64 0.0 5.0 4.0 4.0 3.0 3.0 5.0 6.0
    chart    (item) object 'line' 'line'
    label    (item, state) object 'Array One' 'Array One' ... 'Array Two'
    group    (item) object '' ''
Attributes (0/49):


[4]:

layout#

To layout, simply add the objects to lay them out horizontally or divide the objects to lay them out vertically.

This results in an ah.Data object that contains multiple keys within the wrapped dict.

[5]:
import ahlive as ah
arr1 = ah.Array([0, 1], [4, 5], title='Array One', chart='line')
arr2 = ah.Array([0, 1], [3, 5], title='Array Two', chart='line')
arr3 = ah.Array([0, 1], [7, 8], title='Array Three', chart='line')
layout = (arr1 + arr2) / arr3
print(layout)
layout.render()
<ahlive.Data>
Subplot:         (1, 1)
Dimensions:      (item: 1, state: 2)
Data variables:
    x        (item, state) float64 0.0 1.0
    y        (item, state) float64 4.0 5.0
    chart    (item) <U4 'line'
    label    (item, state) <U1 '' ''
    group    (item) <U1 ''
Attributes (1/49):
    title_kwds   {'label': 'Array One'}

Subplot:         (1, 2)
Dimensions:      (item: 1, state: 2)
Data variables:
    x        (item, state) float64 0.0 1.0
    y        (item, state) float64 3.0 5.0
    chart    (item) <U4 'line'
    label    (item, state) <U1 '' ''
    group    (item) <U1 ''
Attributes (1/49):
    title_kwds   {'label': 'Array Two'}

Subplot:         (2, 1)
Dimensions:      (item: 1, state: 2)
Data variables:
    x        (item, state) float64 0.0 1.0
    y        (item, state) float64 7.0 8.0
    chart    (item) <U4 'line'
    label    (item, state) <U1 '' ''
    group    (item) <U1 ''
Attributes (1/49):
    title_kwds   {'label': 'Array Three'}


gifsicle: warning: trivial adaptive palette (only 199 colors in source)
[5]:

Instead of manually using the divide operator to achieve a vertical layout, the max number of columns can be specified through cols.

Any subplot that exceeds the max number of cols is wrapped to the next row.

[6]:
import ahlive as ah
arr1 = ah.Array([0, 1], [4, 5], title='Array One', chart='line')
arr2 = ah.Array([0, 1], [3, 5], title='Array Two', chart='line')
arr3 = ah.Array([0, 1], [7, 8], title='Array Three', chart='line')
layout = (arr1 + arr2 + arr3).cols(2)
layout.render()
gifsicle: warning: trivial adaptive palette (only 199 colors in source)
[6]:

merge#

To merge a list of objects, use the built-in method, merge specifying the join method.

This is useful for dynamically created objects, such as through list comprehensions.

[7]:
import ahlive as ah
for join in ['overlay', 'cascade']:
    merged = ah.merge([
        ah.Array(
            [0, 1, 2], [i, i + 1, i + 2], title=join
        ) for i in range(0, 3)
    ], join=join)
    merged.render()
gifsicle: warning: trivial adaptive palette (only 88 colors in source)
gifsicle: warning: trivial adaptive palette (only 50 colors in source)