Transforming#

Transform the ahlive objects on the go!

invert#

invert swaps the item and state dimensions.

[1]:
import pandas as pd
import ahlive as ah

df = pd.DataFrame({'x': [1, 2, 3], 'y': [3, 4, 5], 'z': [5, 6, 7]}).melt('x')
ah_df = ah.DataFrame(df, 'x', 'value', label='variable')
ah_df_inv = ah_df.invert()

print('Original', ah_df)
print('Inverted', ah_df_inv)

ah_df.render()
ah_df_inv.render()
Original <ahlive.Data>
Subplot:         (1, 1)
Dimensions:      (item: 2, state: 3)
Data variables:
    x        (item, state) float64 1.0 2.0 3.0 1.0 2.0 3.0
    y        (item, state) float64 3.0 4.0 5.0 5.0 6.0 7.0
    chart    (item) <U7 'scatter' 'scatter'
    label    (item, state) object 'y' 'y' 'y' 'z' 'z' 'z'
    group    (item) <U1 '' ''
Attributes (2/49):
    xlabel_kwds  {'xlabel': 'X'}
    ylabel_kwds  {'ylabel': 'Value'}


Inverted <ahlive.Data>
Subplot:         (1, 1)
Dimensions:      (state: 2, item: 3)
Data variables:
    x            (item, state) float64 1.0 1.0 2.0 2.0 3.0 3.0
    y            (item, state) float64 3.0 5.0 4.0 6.0 5.0 7.0
    chart        (item) object 'scatter' 'scatter' 'scatter'
    label        (item) <U1 '' '' ''
    group        (item) object '' '' ''
    state_label  (state) object 'y' 'z'
Attributes (2/49):
    xlabel_kwds  {'xlabel': 'X'}
    ylabel_kwds  {'ylabel': 'Value'}


gifsicle: warning: trivial adaptive palette (only 57 colors in source)
gifsicle: warning: trivial adaptive palette (only 81 colors in source)
[1]:

label, group, and state_labels all can be passed to the invert method to override existing values.

[2]:
import pandas as pd
import ahlive as ah

df = pd.DataFrame({'x': [1, 2, 3], 'y': [3, 4, 5], 'z': [5, 6, 7]}).melt('x')
ah_df = ah.DataFrame(df, 'x', 'value', label='variable')
ah_df_inv = ah_df.invert(group="A", state_labels=['1', '2'])
ah_df_inv.render()
gifsicle: warning: trivial adaptive palette (only 44 colors in source)
[2]: