Animating

To animate or not to animate, that is the question.

animate

By default, animate is set to True. However, if set to False, the individual frames can be saved to a directory named after save.

[1]:
import ahlive as ah
ah.Array([0, 1], [4, 5], save='exporting_tutorial', animate=False).render()
[########################################] | 100% Completed |  4.3s
[1]:
['/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/01.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/02.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/03.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/04.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/05.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/06.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/07.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/08.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/09.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/10.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/11.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/12.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/13.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/14.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/15.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/16.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/17.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/18.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/19.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/20.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/21.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/22.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/23.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/24.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/25.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/26.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/27.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/28.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/29.png',
 '/home/docs/checkouts/readthedocs.org/user_builds/ahlive/checkouts/main/docs/source/customizations/exporting_tutorial/30.png']

Or, rather than saving to disk, the ouput can be piped to other packages, like panel.

[2]:
import ahlive as ah
import panel as pn
pn.extension()
images = ah.Array([0, 1], [4, 5], animate=False).render()
pngs = [pn.pane.PNG(image, name=str(i)) for i, image in enumerate(images)]
tabs = pn.Tabs(*pngs)
player = pn.widgets.Player(align='center', end=len(tabs))
link = player.jslink(tabs, value='active', bidirectional=True)
pn.Column(tabs, player).servable()
[########################################] | 100% Completed |  4.3s
[2]:

Besides a bool, animate also accepts a Iterable, str, slice, or int.

If an Iterable is passed to animate, only those frames will be animated.

[3]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], animate=[1, 25]).render()
gifsicle: warning: trivial adaptive palette (only 198 colors in source)
[3]:

If head (or tail) is passed, the first (or last) 10 frames will be animated and fps will be set to 1.

[4]:
import ahlive as ah
ah.Array([0, 1], [4, 5], animate='head').render()
[########################################] | 100% Completed |  1.4s
gifsicle: warning: trivial adaptive palette (only 208 colors in source)
[4]:

A number can be suffixed to control the number of frames.

[5]:
import ahlive as ah
ah.Array([0, 1], [4, 5], animate='head_5').render()
gifsicle: warning: trivial adaptive palette (only 206 colors in source)
[5]:

Any arbitrary str will animate 10 frames evenly distributed.

[6]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], animate='test').render()
[########################################] | 100% Completed |  1.6s
gifsicle: warning: trivial adaptive palette (only 205 colors in source)
[6]:

If a slice is passed to animate, only those frames in between the start and stop will be animated at step intervals.

[7]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], animate=slice(0, 40, 5)).render()
[########################################] | 100% Completed |  1.2s
gifsicle: warning: trivial adaptive palette (only 198 colors in source)
[7]:

If an int is passed, only that frame will be rendered, i.e. a static image is produced.

[8]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], animate=28).render()
[8]:

durations

The animations can be slowed down or sped up using durations.

If a scalar is passed to durations all frames will be delayed by the specified value in seconds.

[9]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], durations=2).render()
[########################################] | 100% Completed |  5.7s
gifsicle: warning: trivial adaptive palette (only 206 colors in source)
[9]:

durations is only supported for GIFs!

durations can also be specified as an Iterable. The length must match the number of states.

[10]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], durations=[1e-6, 1, 10]).render()
[########################################] | 100% Completed |  5.7s
gifsicle: warning: trivial adaptive palette (only 206 colors in source)
[10]:

durations only delay the original states. To delay the interpolated frames, transition_frames can be set through config.

[11]:
import ahlive as ah
arr = ah.Array([0, 1], [4, 5])
arr = arr.config('durations', transition_frames=0.5)
arr.render()
[########################################] | 100% Completed |  4.4s
gifsicle: warning: trivial adaptive palette (only 208 colors in source)
[11]:

Setting final_frame can delay the last frame before the animation restarts.

[12]:
import ahlive as ah
arr = ah.Array([0, 1], [4, 5])
arr = arr.config('durations', final_frame=3)
arr.render()
[########################################] | 100% Completed |  4.3s
gifsicle: warning: trivial adaptive palette (only 208 colors in source)
[12]:

fps

Alternatively, animations can be slowed down or sped up using durations.

fps, or frames per second, is the inverse of durations, e.g. 10 fps == 1 / 10 durations.

[13]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], fps=10).render()
[########################################] | 100% Completed |  5.7s
gifsicle: warning: trivial adaptive palette (only 206 colors in source)
[13]:

loop

The number of times the animation plays can be limited with loop.

[14]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], loop=1).render()
[########################################] | 100% Completed |  5.7s
gifsicle: warning: trivial adaptive palette (only 206 colors in source)
[14]:

limits

xlim0s, xlim1s, ylim0s, and ylim1s accept an Iterable, str, or scalar.

If an Iterable is passed, the plots’ limits are animated! The length of the Iterable must match the number of states.

[15]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], xlim1s=[7, 8, 9]).render()
[########################################] | 100% Completed |  5.7s
gifsicle: warning: trivial adaptive palette (only 216 colors in source)
[15]:

If a scalar is passed, the limits are statically set to that value.

[16]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], xlim1s=9).render()
[########################################] | 100% Completed |  5.8s
gifsicle: warning: trivial adaptive palette (only 216 colors in source)
[16]:

There are a couple built-in str options for limits.

fixed sets the limits to the absolute min / max of all items and states.

[17]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], xlim1s='fixed').render()
[########################################] | 100% Completed |  5.7s
gifsicle: warning: trivial adaptive palette (only 207 colors in source)
[17]:

follow follows the current state’s min/max across all items.

[18]:
import ahlive as ah
ah.Array([0, 1, 2, 0], [4, 5, 6, 6], xlim1s='follow').render()
[##########                              ] | 26% Completed |  1.7s
/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/animation.py:1316: UserWarning: Attempting to set identical left == right == 0.0 results in singular transformations; automatically expanding.
[####################################    ] | 91% Completed |  5.6s
/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/animation.py:1316: UserWarning: Attempting to set identical left == right == 0.0 results in singular transformations; automatically expanding.
[########################################] | 100% Completed |  6.2s
gifsicle: warning: trivial adaptive palette (only 251 colors in source)
[18]:

explore is similar to follow except, the min/max doesn’t decrease once explored.

[19]:
import ahlive as ah
ah.Array([0, 1, 2, 0], [4, 5, 6, 6], xlim1s='explore').render()
[###############################         ] | 77% Completed |  4.8s
/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/animation.py:1316: UserWarning: Attempting to set identical left == right == 0.0 results in singular transformations; automatically expanding.
[########################################] | 100% Completed |  6.3s
gifsicle: warning: trivial adaptive palette (only 250 colors in source)
[19]: