Bounding#

It’s easy to bound the extents in the animation!

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.

[1]:
import ahlive as ah
ah.Array([0, 1, 2], [4, 5, 6], xlim1s=[7, 8, 9]).render()
gifsicle: warning: trivial adaptive palette (only 52 colors in source)
[1]:

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

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

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

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

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

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

[4]:
import ahlive as ah
ah.Array([0, 1, 2, 0], [4, 5, 6, 6], xlim1s='follow').render()
gifsicle: warning: trivial adaptive palette (only 55 colors in source)
[4]:

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

[5]:
import ahlive as ah
ah.Array([0, 1, 2, 0], [4, 5, 6, 6], xlim1s='explore').render()
gifsicle: warning: trivial adaptive palette (only 58 colors in source)
[5]:

All these string limits can be suffixed with a desired offset value.

[6]:
import ahlive as ah
ah.Array([0, 1, 2, 0], [4, 5, 6, 6], xlim1s='explore_1').render()
gifsicle: warning: trivial adaptive palette (only 62 colors in source)
[6]:

If xs is a datetime type, a string representing a timedelta value can be passed. Any units listed in `pd.to_timedelta <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_timedelta.html>`__ can be used.

[7]:
import ahlive as ah
import pandas as pd
ah.Array(pd.date_range("2017-02-01", "2017-02-04"), [4, 5, 6, 6], xlim1s='explore_12H').render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/main/lib/python3.11/site-packages/ahlive-1.0.3.post6+dirty-py3.11.egg/ahlive/data.py:1045: UserWarning: Converting non-nanosecond precision timedelta values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.
gifsicle: warning: trivial adaptive palette (only 62 colors in source)
[7]:

If setting xlim0s and xlim1s or ylim0s and ylim1s individually feels tedious, there is the option to set xlims and ylims.

[8]:
import ahlive as ah
ah.Array([0, 1, 2, 0], [4, 5, 6, 6], xlims='explore', ylims='explore').render()
gifsicle: warning: trivial adaptive palette (only 59 colors in source)
[8]:

margins#

On top of setting limits, margins can be set as well. For example, 0.5 pads both the upper and lower limits by 50%.

[9]:
import ahlive as ah
ah.Array([0, 1, 2, 0], [4, 5, 6, 6], xmargins=0.5, ymargins=0.5).render()
gifsicle: warning: trivial adaptive palette (only 56 colors in source)
[9]:

If a tuple is passed, the first value maps to the lower limit and the second value maps to the upper limit.

[10]:
import ahlive as ah
ah.Array([0, 1, 2, 0], [4, 5, 6, 6], xmargins=(0.5, 0), ymargins=(0, 0.5)).render()
gifsicle: warning: trivial adaptive palette (only 63 colors in source)
[10]: