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) <U1 'y' 'z'
    group    (item) <U2 '' ''
    interp   (item) <U5 'cubic' 'cubic'
    ease     (item) <U6 'in_out' 'in_out'
Attributes (2/47):
    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 '' '' ''
    interp       (item) object 'cubic' 'cubic' 'cubic'
    ease         (item) object 'in_out' 'in_out' 'in_out'
    state_label  (state) object 'y' 'z'
Attributes (2/47):
    xlabel_kwds  {'xlabel': 'X'}
    ylabel_kwds  {'ylabel': 'Value'}


[########################################] | 100% Completed |  7.7s
[########################################] | 100% Completed |  5.6s
[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()
[########################################] | 100% Completed |  5.5s
gifsicle: warning: trivial adaptive palette (only 247 colors in source)
[2]: