Charting#

chart keywords#

ahlive has these keywords for various types of charts:

ahlive keyword

description

line

connect data coordinates with a line

scatter

mark data coordinates with symbols

bar

fill data coordinates with vertical rectangles

barh

fill data coordinates with horizontal rectangles

pie

fill data arrays with fractional wedges

errorbar

connect data coordinates with a line plus segments

area

fill data coordinates with regions

annotation

label data coordinates with text

pcolormesh

paints data grids with filled colors

contourf

contour data grids with filled colors

contour

contour data grids with line colors

hexbin

groups data grids as 2D histograms

quiver

draws data grids as arrows

streamplot

draws data grids as streamlines

windbarb

draws data grid as wind barbs

A chart’s behavior may be modified by setting a preset. Learn more in Presetting.

line#

Draws a line, segment by segment, connecting the data points.

[1]:
import ahlive as ah
ah.Array([-5, 0, 5], [1, -1, 0.5], xlims="fixed", chart="line").render()
gifsicle: warning: trivial adaptive palette (only 140 colors in source)
[1]:

scatter#

Draws a symbol that moves one coordinate point at a time.

[2]:
import ahlive as ah
ah.Array([-5, 0, 5], [1, -1, 0.5], xlims="fixed", chart="scatter").render()
gifsicle: warning: trivial adaptive palette (only 48 colors in source)
[2]:

bar#

Draws bars, fusing the data points.

[3]:
import ahlive as ah
ah.Array([-5, 0, 5], [1, -1, 0.5], xlims="fixed", chart="bar").render()
gifsicle: warning: trivial adaptive palette (only 17 colors in source)
[3]:

barh#

Same as bar, but horizontally.

[4]:
import ahlive as ah
ah.Array([-5, 0, 5], [1, -1, 0.5], xlims="fixed", chart="barh").render()
gifsicle: warning: trivial adaptive palette (only 16 colors in source)
[4]:

pie#

Draws a fractionated circle with the area representing the data points.

[5]:
import ahlive as ah
ah.Array([0.5, 0.75, 1], chart="pie").render()
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
<__array_function__ internals>:200: RuntimeWarning: invalid value encountered in cast
gifsicle: warning: trivial adaptive palette (only 153 colors in source)
[5]:

If both xs and ys are passed, xs will be ignored.

errorbar#

Like line, but with vertical or horizontal segments at each base frame.

[6]:
import ahlive as ah
ah.Array(
    [0, 1, 2],
    [1, 2, 3],
    yerrs=[0.25, 0.5, 0.1],
    xlims="fixed",
    chart="errorbar",
).render()
gifsicle: warning: trivial adaptive palette (only 137 colors in source)
[6]:

area#

Fills in regions, step by step.

[7]:
import ahlive as ah
ah.Array(
    [0, 1, 2],
    [3, 2, 1.5],
    y2=[2, 1.5, 1.5],
    xlims="fixed",
    chart="area",
).render()
gifsicle: warning: trivial adaptive palette (only 172 colors in source)
[7]:

annotation#

Have a label follow data coordinates.

[8]:
import ahlive as ah
ah.Array(
    [0, 1, 2],
    [1, 2, 1.5],
    text=["a", "b", "c"],
    xlims="fixed",
    chart="annotation"
).render()
gifsicle: warning: trivial adaptive palette (only 22 colors in source)
[8]:

pcolormesh#

Maps color to each grid cell based on the value.

[9]:
import ahlive as ah
import numpy as np

xs, ys = np.arange(0, 2 * np.pi, .5), np.arange(0, 2 * np.pi, .5)
X, Y = np.meshgrid(xs, ys)
cs = np.stack([np.sin(X), np.cos(X)]) * np.stack([np.sin(Y), np.sin(Y)])

ah.Array2D(xs, ys, cs=cs, chart="pcolormesh").render()
gifsicle: warning: trivial adaptive palette (only 60 colors in source)
[9]:

contourf#

Computes discrete contours and maps color to each interval.

[10]:
import ahlive as ah
import numpy as np

xs, ys = np.arange(0, 2 * np.pi, .5), np.arange(0, 2 * np.pi, .5)
X, Y = np.meshgrid(xs, ys)
cs = np.stack([np.sin(X), np.cos(X)]) * np.stack([np.sin(Y), np.sin(Y)])

ah.Array2D(xs, ys, cs=cs, chart="contourf").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:917: UserWarning: num_colors is ignored for contourf!
gifsicle: warning: trivial adaptive palette (only 66 colors in source)
[10]:

contour#

Like contourf, but not filled.

[11]:
import ahlive as ah
import numpy as np

xs, ys = np.arange(0, 2 * np.pi, .5), np.arange(0, 2 * np.pi, .5)
X, Y = np.meshgrid(xs, ys)
cs = np.stack([np.sin(X), np.cos(X)]) * np.stack([np.sin(Y), np.sin(Y)])

ah.Array2D(xs, ys, cs=cs, chart="contour").render()
[11]:

hexbin#

Groups nearby coordinates into a point, like a 2D histogram.

[12]:
import ahlive as ah
import numpy as np

xs, ys = np.random.randn(2, 100)
cs = np.random.rand(2, 100, 100)

ah.Array2D(xs, ys, cs=cs, gridsize=(10, 5), chart="hexbin").render()
gifsicle: warning: trivial adaptive palette (only 51 colors in source)
[12]:

quiver#

Draws an arrow at each grid point.

[13]:
import ahlive as ah
import numpy as np

xs, ys = np.arange(0, 2 * np.pi, .5), np.arange(0, 2 * np.pi, .5)
X, Y = np.meshgrid(xs, ys)
us = np.stack([np.sin(X), np.cos(X)])
vs = np.stack([np.sin(Y), np.sin(Y)])

ah.Array2D(xs, ys, cs=us * vs, us=us, vs=vs, chart="quiver").render()
[13]:

cs does not have to be specified.

streamplot#

Draws a streamline at each grid point.

[14]:
import ahlive as ah
import numpy as np

xs, ys = np.arange(0, 2 * np.pi, 1), np.arange(0, 2 * np.pi, 1)
X, Y = np.meshgrid(xs, ys)
us = np.stack([np.sin(X), np.cos(X)])
vs = np.stack([np.sin(Y), np.sin(Y)])

ah.Array2D(xs, ys, cs=us * vs, us=us, vs=vs, chart="streamplot").render()
[14]:

windbarb#

Draws a wind barb at each grid point.

[15]:
import ahlive as ah
import numpy as np

xs, ys = np.arange(0, 2 * np.pi, 1), np.arange(0, 2 * np.pi, 1)
X, Y = np.meshgrid(xs, ys)
us = np.stack([np.sin(X), np.cos(X)]) * 50
vs = np.stack([np.sin(Y), np.sin(Y)]) * 50

ah.Array2D(xs, ys, cs=us * vs, us=us, vs=vs, chart="windbarb").render()
[15]: