Charts

Axes, number lines, polar axes, plots and data charts.

Contents:

  • k.PolarAxes: Polar axes (rings and spokes): r=(0, r_max, step), radius= in units, spokes=.
  • k.Axes: Cartesian axes with ticks, labels and an optional grid: x=(min, max, step), y=(min, max), labels=("x", "y"), width=/height= in units.
  • k.Timeline: Events along a time axis: k.Timeline([(1687, "Principia"), ...], range=(1600, 2000)) draws labelled ticks and a marker per event, its label on the first row above or below the axis where it clears the others.
  • k.NumberLine: A horizontal number line: a k.Axes with only the x axis.
  • k.NumberPlane: A coordinate grid with axes and the basis vectors î (green) and ĵ (red): x=(min, max, step), y=..., unit= scene units per step.
  • k.ComplexPlane: A k.NumberPlane labelled as the complex plane (real ticks, i ticks, Re/Im) whose points are complex numbers: cp.dot(2 + 1j), cp.vector(1 - 2j), cp.coords(z).
  • k.vector_sum: Adds two axes vectors tip to tail: b slides so its tail sits on a's tip, then the resultant (a + b) is drawn from a's tail.
  • Plot: A curve y = fn(x) of an axes.
  • k.BarChart: Bar chart from a table: x= is the category column, y= the value column and key= identifies each bar.
  • k.PieChart: One slice per row of a table: labels= names the category column and values= the numbers; donut=0.5 leaves a hole (a fraction of radius=).
  • k.LineChart: A k.Axes with one line per y= column (one or several), connecting the table's points in x= order.
  • k.Table: Table of k.Text with a highlighted header; columns= selects and orders the columns.

Methods in this area:

  • ax.parametric: Parametric curve (fx(t), fy(t)) for t=(start, end); clipped to the visible ranges.
  • numberplane.apply: Animated transformation of the plane, composed after the ones already applied: a matrix [[a, b], [c, d]] sends î to (a, c) and ĵ to (b, d); a function (x, y) -> (x2, y2) bends the grid for non-linear maps.
  • numberplane.polygon: A filled shape with vertices in data coordinates that deforms with the plane.
  • ax.plot: Draws the curve y = fn(x) on the axes, with adaptive sampling.
  • ax.area: Filled region under a curve (down to the x axis) or between two curves (between=).
  • ax.vline: Vertical line on the axes at at= (accepts a signal: the line moves with it); style="dashed" makes it dashed.
  • ax.hline: Horizontal line on the axes at at= (accepts a signal); style="dashed" makes it dashed.
  • ax.scatter: Points (xs[i], ys[i]) on the axes, as a group of k.Dot.
  • ax.zoom_to: Named transition: animates the visible ranges of the axes (x=(a, b), y=(c, d)).
  • ax.point: Data point (x, y) in world coordinates, reactive when x or y are signals.
  • ax.add: Puts objects inside the axes, in its own coordinates, so they follow zooms like plots do; place them with position=ax.local_point(x, y) or ax.origin().
  • ax.segment: A line between two data points (x, y), cut to the visible ranges with clip=True (the default) and hidden when it falls entirely outside them; it follows zooms.
  • ax.hband: ax.hband(y0, y1): a translucent band across the plot between two data values; ax.vband(x0, x1) the same up the plot.
  • ax.vector: An arrow of components v from the data point at=, in data units; both are signals, so vector.to(v=(2, 1)) turns it and it follows zooms.
  • ax.dot: A dot at a data point that follows zooms; open=True draws it hollow (filled with the background) for an endpoint a piecewise function leaves out.
  • ax.origin: Where the two axes cross, in the axes' own coordinates: the data origin clamped to the visible ranges.
  • ax.in_view: Whether a data value is inside the visible ranges, as a reactive bool for visible=: ax.in_view(x=3), ax.in_view(y=5) or both.
  • curve.point_at: World position of the curve at x; reactive when x is a signal.
  • curve.tangent_at: Tangent segment length units long, centered on the curve at x, reactive when x is a signal.
  • curve.slope_at: Numerical derivative of the curve at x, reactive when x is a signal.

Back to the reference index.

k.PolarAxes (class)

k.PolarAxes(
    r: tuple[float, ...] = (0, 1),
    *,
    radius: float = 3.0,
    spokes: int = 12,
    labels: bool = True,
    **props: Unpack[UnplacedKeywords],
)

Polar axes (rings and spokes): r=(0, r_max, step), radius= in units, spokes=. pa.plot(lambda a: r(a)) draws r = f(θ); pa.point(r, θ) gives the world position.

Parameters:

Name Type Default Description
r tuple[float, ...] (0, 1) Polar axes (rings and spokes): r=(0, r_max, step), radius= in units, spokes=.
radius float 3.0 Polar axes (rings and spokes): r=(0, r_max, step), radius= in units, spokes=.
spokes int 12 Polar axes (rings and spokes): r=(0, r_max, step), radius= in units, spokes=.
labels bool True
**props Unpack[UnplacedKeywords] variadic Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis.

Props (animatable with .to(), settable with .set() or in the constructor):

Prop Kind Default Interpolation
r_max float 1.0 linear
radius float 3.0 linear

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

def petals(a: float) -> float:
    return abs(k.cos(3 * a))

@k.scene
def rose(s: k.Scene):
    pa = k.PolarAxes(r=(0, 1, 0.25), radius=3).place(at="center")
    curve = pa.plot(petals, color=k.PINK)
    s.add(pa)
    s.play(k.draw(curve), duration=2)

See also: k.Axes, ax.parametric.

Members:

  • local_point: Point at radius r (data units) and angle theta (radians, from +x), in the axes' own coordinates.
  • point: World position of (r, theta).
  • plot: Curve r = fn(theta) (sampled at build, in the axes' coordinates).

Inherited from k.Group: children, to, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.PolarAxes.local_point (method)

polaraxes.local_point(r: FloatVal, theta: FloatVal) -> Expr[Vec]

Point at radius r (data units) and angle theta (radians, from +x), in the axes' own coordinates.

Parameters:

Name Type Default Description
r FloatVal required Point at radius r (data units) and angle theta (radians, from +x), in the axes' own coordinates.
theta FloatVal required Point at radius r (data units) and angle theta (radians, from +x), in the axes' own coordinates.

k.PolarAxes.point (method)

polaraxes.point(r: FloatVal, theta: FloatVal) -> Expr[Vec]

World position of (r, theta).

Parameters:

Name Type Default Description
r FloatVal required
theta FloatVal required

k.PolarAxes.plot (method)

polaraxes.plot(
    fn: Callable[[float], float],
    *,
    theta: tuple[float, float] = (0.0, 6.283185307179586),
    samples: int = 360,
    color: ColorLike | None = None,
    enter_with_axes: bool = True,
    **style: Unpack[PlotStyleKeywords],
) -> Path

Curve r = fn(theta) (sampled at build, in the axes' coordinates). enter_with_axes=False keeps it hidden until a verb brings it in.

Parameters:

Name Type Default Description
fn Callable[[float], float] required
theta tuple[float, float] (0.0, 6.283185307179586)
samples int 360
color ColorLike | None None
enter_with_axes bool True enter_with_axes=False keeps it hidden until a verb brings it in.
**style Unpack[PlotStyleKeywords] variadic Keyword arguments (PlotStyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke_width: FloatVal, dash: FloatsVal.

k.Axes (class)

k.Axes(
    x: Sequence[float] = (0, 10),
    y: Sequence[float] = (0, 5),
    *,
    labels: tuple[str, str] | None = None,
    grid: bool = False,
    width: float = 8.0,
    height: float = 4.5,
    tick_labels: bool = True,
    x_ticks: Sequence[float] | None = None,
    y_ticks: Sequence[float] | None = None,
    tick_format: TickFormat | None = None,
    **props: Unpack[UnplacedKeywords],
)

Cartesian axes with ticks, labels and an optional grid: x=(min, max, step), y=(min, max), labels=("x", "y"), width=/height= in units. The visible ranges are signals: ax.zoom_to(...) animates them and everything on the axes follows. x_ticks=/y_ticks= set the tick values by hand and tick_format= ("{:.1f}" or a function) writes their labels; y labels are right-aligned to the axis.

Parameters:

Name Type Default Description
x Sequence[float] (0, 10) Cartesian axes with ticks, labels and an optional grid: x=(min, max, step), y=(min, max), labels=("x", "y"), width=/height= in units.
y Sequence[float] (0, 5) Cartesian axes with ticks, labels and an optional grid: x=(min, max, step), y=(min, max), labels=("x", "y"), width=/height= in units.
labels tuple[str, str] | None None Cartesian axes with ticks, labels and an optional grid: x=(min, max, step), y=(min, max), labels=("x", "y"), width=/height= in units.
grid bool False k.Axes(x=(0, 24, 6), y=(0, 7), labels=("h", "kW"), grid=True).
width float 8.0 Cartesian axes with ticks, labels and an optional grid: x=(min, max, step), y=(min, max), labels=("x", "y"), width=/height= in units.
height float 4.5 Cartesian axes with ticks, labels and an optional grid: x=(min, max, step), y=(min, max), labels=("x", "y"), width=/height= in units.
tick_labels bool True
x_ticks Sequence[float] | None None x_ticks=/y_ticks= set the tick values by hand and tick_format= ("{:.1f}" or a function) writes their labels; y labels are right-aligned to the axis.
y_ticks Sequence[float] | None None x_ticks=/y_ticks= set the tick values by hand and tick_format= ("{:.1f}" or a function) writes their labels; y labels are right-aligned to the axis.
tick_format TickFormat | None None x_ticks=/y_ticks= set the tick values by hand and tick_format= ("{:.1f}" or a function) writes their labels; y labels are right-aligned to the axis.
**props Unpack[UnplacedKeywords] variadic Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis.

Props (animatable with .to(), settable with .set() or in the constructor):

Prop Kind Default Interpolation
x_range vec2 (0.0, 1.0) linear
y_range vec2 (0.0, 1.0) linear
size vec2 (8.0, 4.5) linear

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

@k.scene
def axes(s: k.Scene):
    ax = k.Axes(x=(0, 10, 2), y=(0, 5, 1), labels=("t", "v"), grid=True).place(at="center")
    s.play(k.draw(ax))
    s.wait(0.5)

@k.scene
def custom_ticks(s: k.Scene):
    ax = k.Axes(x=(0, 30), y=(0, 1, 0.25), x_ticks=[4, 9, 16, 25], tick_format="{:.2f}").place(at="center")
    s.play(k.draw(ax))

See also: ax.plot, ax.zoom_to, k.NumberLine.

Members:

  • map_x: Data x → x in the axes' own coordinates (reactive: follows zooms).
  • map_y: Data y → y in the axes' own coordinates (reactive: follows zooms).
  • local_point: Data point in the axes' own coordinates.
  • point: Data point (x, y) in world coordinates, reactive when x or y are signals.
  • add: Puts objects inside the axes, in its own coordinates, so they follow zooms like plots do; place them with position=ax.local_point(x, y) or ax.origin().
  • origin: Where the two axes cross, in the axes' own coordinates: the data origin clamped to the visible ranges.
  • in_view: Whether a data value is inside the visible ranges, as a reactive bool for visible=: ax.in_view(x=3), ax.in_view(y=5) or both.
  • plot: Draws the curve y = fn(x) on the axes, with adaptive sampling.
  • dot: A dot at a data point that follows zooms; open=True draws it hollow (filled with the background) for an endpoint a piecewise function leaves out.
  • area: Filled region under a curve (down to the x axis) or between two curves (between=).
  • segment: A line between two data points (x, y), cut to the visible ranges with clip=True (the default) and hidden when it falls entirely outside them; it follows zooms.
  • hband: ax.hband(y0, y1): a translucent band across the plot between two data values; ax.vband(x0, x1) the same up the plot.
  • vband: A vertical band between data x0 and x1, up the plot, cut to the visible x range (hidden outside it); it follows zooms.
  • vector: An arrow of components v from the data point at=, in data units; both are signals, so vector.to(v=(2, 1)) turns it and it follows zooms.
  • vline: Vertical line on the axes at at= (accepts a signal: the line moves with it); style="dashed" makes it dashed.
  • hline: Horizontal line on the axes at at= (accepts a signal); style="dashed" makes it dashed.
  • scatter: Points (xs[i], ys[i]) on the axes, as a group of k.Dot.
  • parametric: Parametric curve (fx(t), fy(t)) for t=(start, end); clipped to the visible ranges.
  • bars: Vertical bars at data xs with data heights (from the x axis); width is in data units.
  • zoom_to: Named transition: animates the visible ranges of the axes (x=(a, b), y=(c, d)).

Inherited from k.Group: children, to, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.Axes.map_x (method)

ax.map_x(x: FloatVal) -> Expr[float]

Data x → x in the axes' own coordinates (reactive: follows zooms).

Parameters:

Name Type Default Description
x FloatVal required

k.Axes.map_y (method)

ax.map_y(y: FloatVal) -> Expr[float]

Data y → y in the axes' own coordinates (reactive: follows zooms).

Parameters:

Name Type Default Description
y FloatVal required

k.Axes.local_point (method)

ax.local_point(x: FloatVal, y: FloatVal) -> Expr[Vec]

Data point in the axes' own coordinates.

Parameters:

Name Type Default Description
x FloatVal required
y FloatVal required

k.Axes.point (method)

ax.point(x: FloatVal, y: FloatVal) -> Expr[Vec]

Data point (x, y) in world coordinates, reactive when x or y are signals. It is the target of place(at=...) for markers on the axes.

Parameters:

Name Type Default Description
x FloatVal required Data point (x, y) in world coordinates, reactive when x or y are signals.
y FloatVal required Data point (x, y) in world coordinates, reactive when x or y are signals.

Example:

@k.scene
def point(s: k.Scene):
    ax = k.Axes(x=(0, 10, 2), y=(0, 10, 2)).place(at="center")
    pin = k.Dot(r=0.12, fill=k.RED).place(at=ax.point(3, 9))
    label = k.Text("(3, 9)", size=0.35).place(right_of=pin, gap=0.2)
    s.play(k.draw(ax))
    s.play(k.fade_in(pin, label))

See also: curve.point_at, obj.place.

k.Axes.add (method)

ax.add(*objs: Node, enter_with_axes: bool = True)

Puts objects inside the axes, in its own coordinates, so they follow zooms like plots do; place them with position=ax.local_point(x, y) or ax.origin(). They enter with the axes; with enter_with_axes=False they stay hidden until a verb brings them in.

Parameters:

Name Type Default Description
*objs Node variadic
enter_with_axes bool True They enter with the axes; with enter_with_axes=False they stay hidden until a verb brings them in.

Example:

@k.scene
def marker(s: k.Scene):
    ax = k.Axes(x=(0, 10, 2), y=(0, 10, 2)).place(at="center")
    peak = k.Dot(r=0.12, fill=k.RED, position=ax.local_point(4, 8))
    ax.add(peak, enter_with_axes=False)
    s.play(k.draw(ax))
    s.play(k.fade_in(peak))
    s.play(ax.zoom_to(x=(2, 6), y=(4, 10)), duration=1.5)

See also: ax.origin, ax.in_view, ax.point.

k.Axes.origin (method)

ax.origin() -> Expr[Vec]

Where the two axes cross, in the axes' own coordinates: the data origin clamped to the visible ranges. Reactive, so it moves with zooms.

Example:

@k.scene
def origin(s: k.Scene):
    ax = k.Axes(x=(-2, 8, 2), y=(-2, 8, 2)).place(at="center")
    ax.add(k.Dot(r=0.1, fill=k.YELLOW, position=ax.origin()))
    s.play(k.draw(ax))
    s.play(ax.zoom_to(x=(2, 8)), duration=1.5)

See also: ax.add, k.Axes.

k.Axes.in_view (method)

ax.in_view(*, x: float | None = None, y: float | None = None) -> Expr[bool]

Whether a data value is inside the visible ranges, as a reactive bool for visible=: ax.in_view(x=3), ax.in_view(y=5) or both. Markers hide when a zoom leaves them out.

Parameters:

Name Type Default Description
x float | None None Whether a data value is inside the visible ranges, as a reactive bool for visible=: ax.in_view(x=3), ax.in_view(y=5) or both.
y float | None None Whether a data value is inside the visible ranges, as a reactive bool for visible=: ax.in_view(x=3), ax.in_view(y=5) or both.

Example:

@k.scene
def in_view(s: k.Scene):
    ax = k.Axes(x=(0, 10, 2), y=(0, 10, 2)).place(at="center")
    tag = k.Text("x = 8", size=0.3, position=ax.local_point(8, 9), visible=ax.in_view(x=8))
    ax.add(tag)
    s.play(k.draw(ax))
    s.play(ax.zoom_to(x=(0, 5)), duration=1.5)

See also: ax.add, ax.zoom_to.

k.Axes.plot (method)

ax.plot(
    fn: PlotFunction,
    *,
    until: FloatExpr | None = None,
    from_: FloatExpr | None = None,
    domain: tuple[float, float] | None = None,
    color: ColorLike | None = None,
    label: str | None = None,
    holes: Sequence[float] = (),
    samples: int = 160,
    enter_with_axes: bool = True,
    **style: Unpack[PlotStyleKeywords],
) -> Plot

Draws the curve y = fn(x) on the axes, with adaptive sampling. fn uses k functions (k.sin, k.max...), so the same function works for floats and signals. until=/from_= accept signals: the curve grows as the signal moves. label= puts a label at the end of the curve.

Parameters:

Name Type Default Description
fn PlotFunction required fn uses k functions (k.sin, k.max...), so the same function works for floats and signals.
until FloatExpr | None None until=/from_= accept signals: the curve grows as the signal moves.
from_ FloatExpr | None None until=/from_= accept signals: the curve grows as the signal moves.
domain tuple[float, float] | None None
color ColorLike | None None
label str | None None label= puts a label at the end of the curve.
holes Sequence[float] () holes=[2] marks points the curve leaves out with open dots (at the limit of fn when it is undefined there; curve.holes).
samples int 160
enter_with_axes bool True enter_with_axes=False keeps it (and its label) hidden until a verb brings it in.
**style Unpack[PlotStyleKeywords] variadic Keyword arguments (PlotStyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke_width: FloatVal, dash: FloatsVal.

Example:

def wave(x: float) -> float:
    return 2 + 1.5 * k.sin(x)

@k.scene
def wave_plot(s: k.Scene):
    ax = k.Axes(x=(0, 10, 2), y=(0, 4, 1)).place(at="center")
    t = k.signal(0.0)
    ax.plot(wave, until=t, color=k.YELLOW, label="wave")
    s.play(k.draw(ax))
    s.play(t.to(10), duration=3, ease=k.ease.linear)

See also: curve.point_at, ax.area, k.sin.

k.Axes.dot (method)

ax.dot(
    x: FloatVal,
    y: FloatVal,
    *,
    open: bool = False,
    radius: float = 0.09,
    enter_with_axes: bool = True,
    **props: Unpack[UnplacedStyleKeywords],
) -> Dot

A dot at a data point that follows zooms; open=True draws it hollow (filled with the background) for an endpoint a piecewise function leaves out. ax.plot(f, holes=[2]) puts open dots on a curve (at the limit of f where it is undefined): curve.holes.

Parameters:

Name Type Default Description
x FloatVal required
y FloatVal required
open bool False A dot at a data point that follows zooms; open=True draws it hollow (filled with the background) for an endpoint a piecewise function leaves out.
radius float 0.09
enter_with_axes bool True
**props Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

@k.scene
def piecewise(s: k.Scene):
    ax = k.Axes(x=(0, 4, 1), y=(0, 6, 1)).place(at="center")
    curve = ax.plot(lambda x: (x * x - 4) / (x - 2), holes=[2])
    ax.dot(3, 1, open=True, color=k.RED)
    ax.dot(3, 5, color=k.RED)
    s.play(k.draw(ax))
    s.play(k.indicate(curve.holes[0]))

See also: ax.plot, ax.segment.

k.Axes.area (method)

ax.area(
    f: Plot | PlotFunction,
    *,
    between: Plot | PlotFunction | None = None,
    domain: tuple[float, float] | None = None,
    until: FloatExpr | None = None,
    samples: int = 200,
    enter_with_axes: bool = True,
    **style: Unpack[StyleKeywords],
) -> Area

Filled region under a curve (down to the x axis) or between two curves (between=). Accepts a curve from ax.plot or a function, plus style (fill=, fill_opacity=).

Parameters:

Name Type Default Description
f Plot | PlotFunction required Filled region under f (to the x axis) or between f and between.
between Plot | PlotFunction | None None Filled region under a curve (down to the x axis) or between two curves (between=).
domain tuple[float, float] | None None
until FloatExpr | None None
samples int 200
enter_with_axes bool True
**style Unpack[StyleKeywords] variadic Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

def f(x: float) -> float:
    return 0.1 * x * x

@k.scene
def area(s: k.Scene):
    ax = k.Axes(x=(0, 6, 1), y=(0, 4, 1)).place(at="center")
    curve = ax.plot(f, color=k.BLUE)
    ax.area(curve, domain=(1, 5), fill=k.BLUE, fill_opacity=0.3)
    s.play(k.draw(ax))
    s.wait(0.5)

See also: ax.plot.

k.Axes.segment (method)

ax.segment(
    start: tuple[float, float],
    end: tuple[float, float],
    *,
    clip: bool = True,
    enter_with_axes: bool = True,
    **props: Unpack[StyleKeywords],
) -> Line

A line between two data points (x, y), cut to the visible ranges with clip=True (the default) and hidden when it falls entirely outside them; it follows zooms.

Parameters:

Name Type Default Description
start tuple[float, float] required
end tuple[float, float] required
clip bool True A line between two data points (x, y), cut to the visible ranges with clip=True (the default) and hidden when it falls entirely outside them; it follows zooms.
enter_with_axes bool True
**props Unpack[StyleKeywords] variadic Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

@k.scene
def secant(s: k.Scene):
    ax = k.Axes(x=(0, 10, 2), y=(0, 10, 2)).place(at="center")
    ax.plot(lambda x: 0.1 * x * x)
    line = ax.segment((-2, -1), (12, 11), stroke=k.YELLOW)
    s.play(k.draw(ax))
    s.play(k.indicate(line))
    s.play(ax.zoom_to(x=(4, 10), y=(4, 10)), duration=1.5)

See also: ax.hband, ax.zoom_to.

k.Axes.hband (method)

ax.hband(
    y0: float,
    y1: float,
    *,
    enter_with_axes: bool = True,
    **props: Unpack[UnplacedStyleKeywords],
) -> Rect

ax.hband(y0, y1): a translucent band across the plot between two data values; ax.vband(x0, x1) the same up the plot. Cut to the visible range, hidden outside it, following zooms. Style with fill=, fill_opacity=.

Parameters:

Name Type Default Description
y0 float required A horizontal band between data y0 and y1, across the plot, cut to the visible y range (hidden outside it); it follows zooms.
y1 float required A horizontal band between data y0 and y1, across the plot, cut to the visible y range (hidden outside it); it follows zooms.
enter_with_axes bool True
**props Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

@k.scene
def comfort(s: k.Scene):
    ax = k.Axes(x=(0, 24, 6), y=(0, 30, 10), labels=("h", "°C")).place(at="center")
    ax.hband(18, 24)
    ax.vband(9, 17, fill=k.GREEN)
    ax.plot(lambda h: 15 + 8 * k.sin((h - 9) * 3.14159 / 12))
    s.play(k.draw(ax))

See also: ax.segment, ax.vline.

k.Axes.vband (method)

ax.vband(
    x0: float,
    x1: float,
    *,
    enter_with_axes: bool = True,
    **props: Unpack[UnplacedStyleKeywords],
) -> Rect

A vertical band between data x0 and x1, up the plot, cut to the visible x range (hidden outside it); it follows zooms.

Parameters:

Name Type Default Description
x0 float required A vertical band between data x0 and x1, up the plot, cut to the visible x range (hidden outside it); it follows zooms.
x1 float required A vertical band between data x0 and x1, up the plot, cut to the visible x range (hidden outside it); it follows zooms.
enter_with_axes bool True
**props Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

k.Axes.vector (method)

ax.vector(
    v: tuple[FloatVal, FloatVal],
    at: tuple[FloatVal, FloatVal] = (0.0, 0.0),
    *,
    label: str | None = None,
    components: bool = False,
    color: ColorLike | None = None,
    size: float = 0.3,
    enter_with_axes: bool = True,
) -> AxesVector

An arrow of components v from the data point at=, in data units; both are signals, so vector.to(v=(2, 1)) turns it and it follows zooms. components=True adds its dashed x and y components (labelled with label=). a + b is the resultant, shown tip to tail by k.vector_sum(a, b, a + b).

Parameters:

Name Type Default Description
v tuple[FloatVal, FloatVal] required An arrow of components v from the data point at=, in data units; both are signals, so vector.to(v=(2, 1)) turns it and it follows zooms.
at tuple[FloatVal, FloatVal] (0.0, 0.0) An arrow of components v from the data point at=, in data units; both are signals, so vector.to(v=(2, 1)) turns it and it follows zooms.
label str | None None components=True adds its dashed x and y components (labelled with label=).
components bool False components=True adds its dashed x and y components (labelled with label=).
color ColorLike | None None
size float 0.3
enter_with_axes bool True

Example:

@k.scene
def forces(s: k.Scene):
    ax = k.Axes(x=(-1, 6, 1), y=(-1, 5, 1), grid=True).place(at="center")
    a = ax.vector((3, 1), label="F", components=True)
    b = ax.vector((1, 2.5), label="G")
    s.play(k.draw(ax))
    s.play(k.vector_sum(a, b, a + b))

See also: k.vector_sum, k.Arrow.

k.Axes.vline (method)

ax.vline(
    at: FloatVal,
    *,
    style: LineStyle = "solid",
    enter_with_axes: bool = True,
    **props: Unpack[StyleKeywords],
) -> Line

Vertical line on the axes at at= (accepts a signal: the line moves with it); style="dashed" makes it dashed.

Parameters:

Name Type Default Description
at FloatVal required Vertical line on the axes at at= (accepts a signal: the line moves with it); style="dashed" makes it dashed.
style LineStyle "solid" Vertical line on the axes at at= (accepts a signal: the line moves with it); style="dashed" makes it dashed.
enter_with_axes bool True
**props Unpack[StyleKeywords] variadic Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

@k.scene
def marker(s: k.Scene):
    ax = k.Axes(x=(0, 24, 6), y=(0, 5)).place(at="center")
    hour = k.signal(6.0)
    ax.vline(at=hour, style="dashed", stroke=k.YELLOW)
    s.play(k.draw(ax))
    s.play(hour.to(18), duration=2)

See also: ax.hline, ax.plot.

k.Axes.hline (method)

ax.hline(
    at: FloatVal,
    *,
    style: LineStyle = "solid",
    enter_with_axes: bool = True,
    **props: Unpack[StyleKeywords],
) -> Line

Horizontal line on the axes at at= (accepts a signal); style="dashed" makes it dashed. Good for limits and targets.

Parameters:

Name Type Default Description
at FloatVal required Horizontal line on the axes at at= (accepts a signal); style="dashed" makes it dashed.
style LineStyle "solid" Horizontal line on the axes at at= (accepts a signal); style="dashed" makes it dashed.
enter_with_axes bool True
**props Unpack[StyleKeywords] variadic Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

@k.scene
def limit(s: k.Scene):
    ax = k.Axes(x=(0, 10, 2), y=(0, 5, 1)).place(at="center")
    ax.hline(at=4, style="dashed", stroke=k.RED)
    s.play(k.draw(ax))
    s.wait(0.5)

See also: ax.vline.

k.Axes.scatter (method)

ax.scatter(
    xs: FloatColumn,
    ys: FloatColumn,
    *,
    radius: float = 0.06,
    enter_with_axes: bool = True,
    **props: Unpack[UnplacedStyleKeywords],
) -> Group[Dot]

Points (xs[i], ys[i]) on the axes, as a group of k.Dot. Accepts lists, numpy arrays and Arrow columns (polars, pandas, pyarrow).

Parameters:

Name Type Default Description
xs FloatColumn required
ys FloatColumn required
radius float 0.06
enter_with_axes bool True
**props Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

@k.scene
def scatter(s: k.Scene):
    ax = k.Axes(x=(0, 5, 1), y=(0, 5, 1)).place(at="center")
    pts = ax.scatter([1, 2, 3, 4], [1.5, 2.2, 3.1, 3.8], radius=0.1, fill=k.TEAL)
    s.play(k.draw(ax))
    s.play(k.indicate(pts))

See also: ax.plot, k.Dot.

k.Axes.parametric (method)

ax.parametric(
    fx: PlotFunction,
    fy: PlotFunction,
    *,
    t: tuple[float, float] = (0.0, 6.283185307179586),
    samples: int = 300,
    color: ColorLike | None = None,
    enter_with_axes: bool = True,
    **style: Unpack[PlotStyleKeywords],
) -> ParametricPlot

Parametric curve (fx(t), fy(t)) for t=(start, end); clipped to the visible ranges. Siblings: ax.bars(xs, heights, width=) (bars in data units) and ax.scatter(xs, ys).

Parameters:

Name Type Default Description
fx PlotFunction required
fy PlotFunction required
t tuple[float, float] (0.0, 6.283185307179586) Parametric curve (fx(t), fy(t)) for t=(start, end); clipped to the visible ranges.
samples int 300
color ColorLike | None None
enter_with_axes bool True
**style Unpack[PlotStyleKeywords] variadic Keyword arguments (PlotStyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke_width: FloatVal, dash: FloatsVal.

Example:

def fx(t: float) -> float:
    return k.sin(2 * t)

def fy(t: float) -> float:
    return k.sin(3 * t)

@k.scene
def loop(s: k.Scene):
    ax = k.Axes(x=(-1.5, 1.5), y=(-1.5, 1.5), width=5, height=5).place(at="center")
    curve = ax.parametric(fx, fy, color=k.TEAL)
    s.add(ax)
    s.play(k.draw(curve), duration=2)

See also: ax.plot, k.Axes.

k.Axes.bars (method)

ax.bars(
    xs: FloatColumn,
    heights: FloatColumn,
    *,
    width: float = 0.6,
    enter_with_axes: bool = True,
    **props: Unpack[UnplacedStyleKeywords],
) -> Group[Node]

Vertical bars at data xs with data heights (from the x axis); width is in data units. Bars follow the axes when it zooms.

Parameters:

Name Type Default Description
xs FloatColumn required Vertical bars at data xs with data heights (from the x axis); width is in data units.
heights FloatColumn required Vertical bars at data xs with data heights (from the x axis); width is in data units.
width float 0.6 Vertical bars at data xs with data heights (from the x axis); width is in data units.
enter_with_axes bool True
**props Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

k.Axes.zoom_to (method)

ax.zoom_to(
    *,
    x: Sequence[float] | None = None,
    y: Sequence[float] | None = None,
    **kw: Unpack[AnimationTiming],
) -> Animation

Named transition: animates the visible ranges of the axes (x=(a, b), y=(c, d)). Curves, ticks and points follow, and ticks are regenerated with a nice step for the new ranges: new ones grow in, ones that no longer fit fade out. Equivalent to ax.to(x_range=..., y_range=...) plus the tick change.

Parameters:

Name Type Default Description
x Sequence[float] | None None Named transition: animates the visible ranges of the axes (x=(a, b), y=(c, d)).
y Sequence[float] | None None Named transition: animates the visible ranges of the axes (x=(a, b), y=(c, d)).
**kw Unpack[AnimationTiming] variadic Keyword arguments (AnimationTiming): duration: float | None, ease: EaseLike | None, delay: float.

Example:

@k.scene
def zoom(s: k.Scene):
    ax = k.Axes(x=(-4, 4, 1), y=(-1, 9, 1)).place(at="center")
    ax.plot(lambda x: x * x, color=k.YELLOW)
    s.play(k.draw(ax))
    s.play(ax.zoom_to(x=(0, 2), y=(0, 4)), duration=1.5)

See also: k.Axes, ax.plot.

k.Timeline (class)

k.Timeline(
    events: Sequence[tuple[float, str]],
    *,
    range: tuple[float, float] | None = None,
    step: float | None = None,
    width: float = 12.0,
    reveal: bool = False,
    color: ColorLike | None = None,
    size: float = 0.26,
    **props: Unpack[UnplacedKeywords],
)

Events along a time axis: k.Timeline([(1687, "Principia"), ...], range=(1600, 2000)) draws labelled ticks and a marker per event, its label on the first row above or below the axis where it clears the others. reveal=True keeps events hidden until tl.reveal(name); tl.zoom_to(range=(a, b)) pans and zooms (ticks are regenerated, events out of view hide). tl.event(name) is an event (.marker, .stem, .label).

Parameters:

Name Type Default Description
events Sequence[tuple[float, str]] required
range tuple[float, float] | None None Events along a time axis: k.Timeline([(1687, "Principia"), ...], range=(1600, 2000)) draws labelled ticks and a marker per event, its label on the first row above or below the axis where it clears the others.
step float | None None
width float 12.0
reveal bool False reveal=True keeps events hidden until tl.reveal(name); tl.zoom_to(range=(a, b)) pans and zooms (ticks are regenerated, events out of view hide).
color ColorLike | None None
size float 0.26
**props Unpack[UnplacedKeywords] variadic Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis.

Props inherited from k.Axes: x_range, y_range, size.

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

EVENTS = [(1687, "Principia"), (1859, "Darwin"), (1865, "Maxwell"), (1905, "Relativity")]

@k.scene
def history(s: k.Scene):
    tl = k.Timeline(EVENTS, range=(1650, 1950), reveal=True).place(at="center")
    s.play(k.draw(tl))
    for _, name in EVENTS:
        s.play(tl.reveal(name), duration=0.4)
    s.play(tl.zoom_to(range=(1680, 1920)), duration=1.5)

See also: k.NumberLine, ax.zoom_to.

Members:

  • event: The event labelled name.
  • reveal: Show an event (for a timeline made with reveal=True).
  • zoom_to: Pan and zoom to the time span range=(start, end).

Inherited from k.Axes: map_x, map_y, local_point, point, add, origin, in_view, plot, dot, area, segment, hband, vband, vector, vline, hline, scatter, parametric, bars. Inherited from k.Group: children, to, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.Timeline.event (method)

timeline.event(name: str) -> TimelineEvent

The event labelled name.

Parameters:

Name Type Default Description
name str required The event labelled name.

k.Timeline.reveal (method)

timeline.reveal(name: str, **kw: Unpack[AnimationTiming]) -> Animation

Show an event (for a timeline made with reveal=True).

Parameters:

Name Type Default Description
name str required
**kw Unpack[AnimationTiming] variadic Keyword arguments (AnimationTiming): duration: float | None, ease: EaseLike | None, delay: float.

k.Timeline.zoom_to (method)

timeline.zoom_to(
    *,
    range: tuple[float, float] | None = None,
    x: Sequence[float] | None = None,
    y: Sequence[float] | None = None,
    **kw: Unpack[AnimationTiming],
) -> Animation

Pan and zoom to the time span range=(start, end).

Parameters:

Name Type Default Description
range tuple[float, float] | None None Pan and zoom to the time span range=(start, end).
x Sequence[float] | None None
y Sequence[float] | None None
**kw Unpack[AnimationTiming] variadic Keyword arguments (AnimationTiming): duration: float | None, ease: EaseLike | None, delay: float.

k.NumberLine (class)

k.NumberLine(
    x: Sequence[float] = (0, 10, 1),
    *,
    width: float = 10.0,
    **props: Unpack[UnplacedKeywords],
)

A horizontal number line: a k.Axes with only the x axis. Use nl.point(x, 0) to position markers.

Parameters:

Name Type Default Description
x Sequence[float] (0, 10, 1)
width float 10.0
**props Unpack[UnplacedKeywords] variadic Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis.

Props inherited from k.Axes: x_range, y_range, size.

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

@k.scene
def number_line(s: k.Scene):
    nl = k.NumberLine(x=(-3, 3, 1), width=10).place(at="center")
    x = k.signal(-2.0)
    dot = k.Dot(r=0.15, fill=k.RED).place(at=nl.point(x, 0))
    s.play(k.draw(nl), k.fade_in(dot))
    s.play(x.to(2), duration=2)

See also: k.Axes, ax.point.

Inherited from k.Axes: map_x, map_y, local_point, point, add, origin, in_view, plot, dot, area, segment, hband, vband, vector, vline, hline, scatter, parametric, bars, zoom_to. Inherited from k.Group: children, to, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.NumberPlane (class)

k.NumberPlane(
    x: Sequence[float] = (-7, 7, 1),
    y: Sequence[float] = (-4, 4, 1),
    *,
    unit: float = 1.0,
    basis: bool = True,
    samples: int = 24,
    color: ColorLike | None = None,
    **props: Unpack[UnplacedKeywords],
)

A coordinate grid with axes and the basis vectors î (green) and ĵ (red): x=(min, max, step), y=..., unit= scene units per step. plane.apply(matrix) deforms it; plane.vector(x, y), plane.dot(x, y), plane.polygon(points) and plane.add(obj, at=(x, y)) put objects on it that the transformations carry.

Parameters:

Name Type Default Description
x Sequence[float] (-7, 7, 1) A coordinate grid with axes and the basis vectors î (green) and ĵ (red): x=(min, max, step), y=..., unit= scene units per step.
y Sequence[float] (-4, 4, 1) A coordinate grid with axes and the basis vectors î (green) and ĵ (red): x=(min, max, step), y=..., unit= scene units per step.
unit float 1.0 A coordinate grid with axes and the basis vectors î (green) and ĵ (red): x=(min, max, step), y=..., unit= scene units per step.
basis bool True
samples int 24
color ColorLike | None None
**props Unpack[UnplacedKeywords] variadic Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis.

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

@k.scene
def plane(s: k.Scene):
    plane = k.NumberPlane(x=(-6, 6, 1), y=(-3, 3, 1))
    v = plane.vector(2, 1, color=k.YELLOW)
    s.play(k.draw(plane))
    s.play(k.indicate(v))

See also: numberplane.apply, numberplane.polygon, k.Axes.

Members:

  • coords: Where the data point (x, y) is now, in the plane's own coordinates (after the transformations applied so far).
  • vector: An arrow from the origin to (x, y) that the transformations carry.
  • dot: A dot at (x, y) that the transformations carry.
  • polygon: A filled shape with vertices in data coordinates that deforms with the plane.
  • add: Put an object on the plane at the data point at: transformations move it (its shape stays as it is; use plane.polygon for shapes that deform).
  • apply: Animated transformation of the plane, composed after the ones already applied: a matrix [[a, b], [c, d]] sends î to (a, c) and ĵ to (b, d); a function (x, y) -> (x2, y2) bends the grid for non-linear maps.
  • reset: Animated return to the untransformed plane.

Inherited from k.Group: children, to, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.NumberPlane.coords (method)

numberplane.coords(x: float, y: float) -> tuple[float, float]

Where the data point (x, y) is now, in the plane's own coordinates (after the transformations applied so far).

Parameters:

Name Type Default Description
x float required
y float required

k.NumberPlane.vector (method)

numberplane.vector(x: float, y: float, **style: Unpack[UnplacedStyleKeywords]) -> Arrow

An arrow from the origin to (x, y) that the transformations carry.

Parameters:

Name Type Default Description
x float required
y float required
**style Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

k.NumberPlane.dot (method)

numberplane.dot(
    x: float,
    y: float,
    *,
    radius: float = 0.1,
    **style: Unpack[UnplacedStyleKeywords],
) -> Dot

A dot at (x, y) that the transformations carry.

Parameters:

Name Type Default Description
x float required
y float required
radius float 0.1
**style Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

k.NumberPlane.polygon (method)

numberplane.polygon(
    points: Sequence[tuple[float, float]],
    **style: Unpack[UnplacedStyleKeywords],
) -> Polygon

A filled shape with vertices in data coordinates that deforms with the plane. The unit square shows the determinant: its area after apply(m) is det(m).

Parameters:

Name Type Default Description
points Sequence[tuple[float, float]] required
**style Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

@k.scene
def determinant(s: k.Scene):
    plane = k.NumberPlane(x=(-6, 6, 1), y=(-3, 3, 1))
    square = plane.polygon([(0, 0), (1, 0), (1, 1), (0, 1)], fill=k.YELLOW)
    s.play(k.draw(plane))
    s.play(plane.apply([[2, 1], [0, 1.5]]), duration=2)
    s.play(k.indicate(square))  # area 3 = det

See also: numberplane.apply, k.NumberPlane.

k.NumberPlane.add (method)

numberplane.add(obj: NodeT, *, at: tuple[float, float]) -> NodeT

Put an object on the plane at the data point at: transformations move it (its shape stays as it is; use plane.polygon for shapes that deform).

Parameters:

Name Type Default Description
obj NodeT required
at tuple[float, float] required Put an object on the plane at the data point at: transformations move it (its shape stays as it is; use plane.polygon for shapes that deform).

k.NumberPlane.apply (method)

numberplane.apply(transform: PlaneTransform, **kw: Unpack[AnimationTiming]) -> Animation

Animated transformation of the plane, composed after the ones already applied: a matrix [[a, b], [c, d]] sends î to (a, c) and ĵ to (b, d); a function (x, y) -> (x2, y2) bends the grid for non-linear maps. Grid lines, basis vectors and the objects made on the plane all move. plane.reset() goes back.

Parameters:

Name Type Default Description
transform PlaneTransform required
**kw Unpack[AnimationTiming] variadic Keyword arguments (AnimationTiming): duration: float | None, ease: EaseLike | None, delay: float.

Example:

import math
import kinemo as k

@k.scene
def shear(s: k.Scene):
    plane = k.NumberPlane(x=(-6, 6, 1), y=(-3, 3, 1))
    eigen = plane.vector(1, 0, color=k.YELLOW)
    s.play(k.draw(plane))
    s.play(plane.apply([[1, 1], [0, 1]]), duration=2)
    s.play(k.indicate(eigen))  # an eigenvector: still on its span
    s.play(plane.apply(lambda x, y: (x + 0.3 * math.sin(y), y)), duration=2)
    s.play(plane.reset())

See also: k.NumberPlane, numberplane.polygon.

k.NumberPlane.reset (method)

numberplane.reset(**kw: Unpack[AnimationTiming]) -> Animation

Animated return to the untransformed plane.

Parameters:

Name Type Default Description
**kw Unpack[AnimationTiming] variadic Keyword arguments (AnimationTiming): duration: float | None, ease: EaseLike | None, delay: float.

k.ComplexPlane (class)

k.ComplexPlane(
    re: Sequence[float] = (-6, 6, 1),
    im: Sequence[float] = (-3, 3, 1),
    *,
    unit: float = 1.0,
    labels: bool = True,
    samples: int = 24,
    **props: Unpack[UnplacedKeywords],
)

A k.NumberPlane labelled as the complex plane (real ticks, i ticks, Re/Im) whose points are complex numbers: cp.dot(2 + 1j), cp.vector(1 - 2j), cp.coords(z). cp.apply(1j) multiplies everything by a complex number (a quarter turn), cp.apply(lambda z: z ** 2) maps the plane with a function of z.

Parameters:

Name Type Default Description
re Sequence[float] (-6, 6, 1) k.ComplexPlane(re=(-4, 4, 1), im=(-3, 3, 1)): the plane with real ticks along the real axis, i ticks along the imaginary one and Re/Im labels.
im Sequence[float] (-3, 3, 1) k.ComplexPlane(re=(-4, 4, 1), im=(-3, 3, 1)): the plane with real ticks along the real axis, i ticks along the imaginary one and Re/Im labels.
unit float 1.0
labels bool True
samples int 24
**props Unpack[UnplacedKeywords] variadic Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis.

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

@k.scene
def rotation(s: k.Scene):
    cp = k.ComplexPlane(re=(-4, 4, 1), im=(-3, 3, 1))
    cp.vector(2 + 1j, color=k.YELLOW)
    s.play(k.draw(cp))
    s.play(cp.apply(1j), duration=2)

See also: k.NumberPlane, numberplane.apply.

Members:

  • coords: Where the complex number value is now, in the plane's own coordinates.
  • dot: A dot at the complex number value that the transformations carry.
  • vector: An arrow from 0 to the complex number value that the transformations carry.
  • apply: Multiply the plane by a complex number (cp.apply(1j): a quarter turn), or map it with a function of z (cp.apply(lambda z: z ** 2)); a 2×2 matrix also works.

Inherited from k.NumberPlane: polygon, add, reset. Inherited from k.Group: children, to, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.ComplexPlane.coords (method)

complexplane.coords(value: complex) -> tuple[float, float]

Where the complex number value is now, in the plane's own coordinates.

Parameters:

Name Type Default Description
value complex required Where the complex number value is now, in the plane's own coordinates.

k.ComplexPlane.dot (method)

complexplane.dot(
    value: complex,
    *,
    radius: float = 0.1,
    **style: Unpack[UnplacedStyleKeywords],
) -> Dot

A dot at the complex number value that the transformations carry.

Parameters:

Name Type Default Description
value complex required A dot at the complex number value that the transformations carry.
radius float 0.1
**style Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

k.ComplexPlane.vector (method)

complexplane.vector(value: complex, **style: Unpack[UnplacedStyleKeywords]) -> Arrow

An arrow from 0 to the complex number value that the transformations carry.

Parameters:

Name Type Default Description
value complex required An arrow from 0 to the complex number value that the transformations carry.
**style Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

k.ComplexPlane.apply (method)

complexplane.apply(
    transform: ComplexTransform | PlaneTransform,
    **kw: Unpack[AnimationTiming],
) -> Animation

Multiply the plane by a complex number (cp.apply(1j): a quarter turn), or map it with a function of z (cp.apply(lambda z: z ** 2)); a 2×2 matrix also works.

Parameters:

Name Type Default Description
transform ComplexTransform | PlaneTransform required
**kw Unpack[AnimationTiming] variadic Keyword arguments (AnimationTiming): duration: float | None, ease: EaseLike | None, delay: float.

k.vector_sum (function)

k.vector_sum(
    a: AxesVector,
    b: AxesVector,
    resultant: AxesVector,
    *,
    duration: float = 1.0,
) -> Animation

Adds two axes vectors tip to tail: b slides so its tail sits on a's tip, then the resultant (a + b) is drawn from a's tail.

Parameters:

Name Type Default Description
a AxesVector required Adds two axes vectors tip to tail: b slides so its tail sits on a's tip, then the resultant (a + b) is drawn from a's tail.
b AxesVector required Adds two axes vectors tip to tail: b slides so its tail sits on a's tip, then the resultant (a + b) is drawn from a's tail.
resultant AxesVector required Adds two vectors tip to tail: b slides so its tail sits on a's tip, then resultant (from a + b) is drawn from a's tail to the end of the chain.
duration float 1.0

Example:

@k.scene
def resultant(s: k.Scene):
    ax = k.Axes(x=(0, 6, 1), y=(0, 4, 1)).place(at="center")
    a, b = ax.vector((3, 0), label="a"), ax.vector((1, 3), label="b")
    s.play(k.draw(ax))
    s.play(k.vector_sum(a, b, a + b, duration=0.8))

See also: ax.vector.

Plot (class)

Plot(
    axes: Axes,
    fn: PlotFunction,
    segments: list[list[tuple[float, float]]],
    clip: Vec | Expr[Vec],
    **props: Unpack[StyleKeywords],
)

A curve y = fn(x) of an axes. Grows with until=; follows the axes when it zooms.

Parameters:

Name Type Default Description
axes Axes required
fn PlotFunction required
segments list[list[tuple[float, float]]] required
clip Vec | Expr[Vec] required
**props Unpack[StyleKeywords] variadic Keyword arguments (StyleKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Props (animatable with .to(), settable with .set() or in the constructor):

Prop Kind Default Interpolation
fill color theme.fg linear
fill_opacity float 0.0 linear
stroke color theme.fg linear
stroke_width float theme.stroke_width linear
dash floats () step_end
glow float 0.0 linear
glow_color color theme.no_color linear
points segments [] step_end
x_range vec2 (0.0, 1.0) linear
y_range vec2 (0.0, 1.0) linear
size vec2 (1.0, 1.0) linear
clip vec2 (-1e+300, 1e+300) linear

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Members:

  • point_at: World position of the curve at x; reactive when x is a signal.
  • value_at: Function value at x (an expression when x is a signal).
  • slope_at: Numerical derivative of the curve at x, reactive when x is a signal.
  • tangent_at: Tangent segment length units long, centered on the curve at x, reactive when x is a signal.

Inherited from k.Node: set, to, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

Plot.point_at (method)

curve.point_at(x: FloatExpr) -> Expr[Vec]

World position of the curve at x; reactive when x is a signal. With place(at=...) it makes a dot slide along the curve. curve.value_at(x) gives the y value.

Parameters:

Name Type Default Description
x FloatExpr required World position of the curve at x; reactive when x is a signal.

Example:

def f(x: float) -> float:
    return 0.15 * x**3 - 0.9 * x + 1.5

@k.scene
def slide(s: k.Scene):
    ax = k.Axes(x=(-3, 3, 1), y=(-1, 5, 1)).place(at="center")
    curve = ax.plot(f, color=k.YELLOW)
    x = k.signal(-2.0)
    dot = k.Dot(r=0.1, fill=k.RED).place(at=curve.point_at(x))
    s.play(k.draw(ax), k.fade_in(dot))
    s.play(x.to(2.5), duration=3)

See also: curve.tangent_at, curve.slope_at, ax.point.

Plot.value_at (method)

curve.value_at(x: float) -> float
curve.value_at(x: Expr[float]) -> Expr[float]

Function value at x (an expression when x is a signal).

Parameters:

Name Type Default Description
x float required Function value at x (an expression when x is a signal).

Plot.slope_at (method)

curve.slope_at(x: FloatExpr) -> Expr[float]

Numerical derivative of the curve at x, reactive when x is a signal. Use it inside lambdas with a tracked read: curve.slope_at(x)().

Parameters:

Name Type Default Description
x FloatExpr required Numerical derivative of the curve at x, reactive when x is a signal.

Example:

@k.scene
def slope(s: k.Scene):
    ax = k.Axes(x=(-3, 3, 1), y=(-1, 9, 1)).place(at="center")
    curve = ax.plot(lambda x: x * x, color=k.YELLOW)
    x = k.signal(-2.0)
    label = k.Text(lambda: f"f'({x():.1f}) = {curve.slope_at(x)():.1f}").place(at="top", margin=0.5)
    s.play(k.draw(ax), k.fade_in(label))
    s.play(x.to(2), duration=3)

See also: curve.tangent_at.

Plot.tangent_at (method)

curve.tangent_at(
    x: FloatExpr,
    length: float = 2.0,
    *,
    enter_with_axes: bool = True,
    **style: Unpack[UnplacedStyleKeywords],
) -> Line

Tangent segment length units long, centered on the curve at x, reactive when x is a signal. It belongs to the axes and enters with it; enter_with_axes=False keeps it hidden until a verb brings it in. Accepts style (stroke=).

Parameters:

Name Type Default Description
x FloatExpr required Tangent segment length units long, centered on the curve at x, reactive when x is a signal.
length float 2.0 Tangent segment length units long, centered on the curve at x, reactive when x is a signal.
enter_with_axes bool True It belongs to the axes and enters with it; enter_with_axes=False keeps it hidden until a verb brings it in.
**style Unpack[UnplacedStyleKeywords] variadic Keyword arguments (UnplacedStyleKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, fill: ColorVal, fill_opacity: FloatVal, stroke: ColorVal, stroke_width: FloatVal, dash: FloatsVal, glow: FloatVal, glow_color: ColorVal, color: ColorVal.

Example:

@k.scene
def tangent(s: k.Scene):
    ax = k.Axes(x=(-3, 3, 1), y=(-1, 9, 1)).place(at="center")
    curve = ax.plot(lambda x: x * x, color=k.YELLOW)
    x = k.signal(-2.0)
    curve.tangent_at(x, length=3, stroke=k.RED)
    s.play(k.draw(ax))
    s.play(x.to(2), duration=3)

See also: curve.slope_at, curve.point_at.

k.BarChart (class)

k.BarChart(
    data: DataTable,
    x: str,
    y: str,
    *,
    key: str | None = None,
    width: float = 8.0,
    height: float = 4.5,
    color: ColorLike | Mapping[str, ColorLike] | None = None,
    labels: bool = True,
    grid: bool = False,
    bar_ratio: float = 0.7,
    label_size: float = 0.28,
    **props: Unpack[ChartKeywords],
)

Bar chart from a table: x= is the category column, y= the value column and key= identifies each bar. Accepts Arrow sources without copying (polars, pandas, pyarrow, duckdb), dicts of lists and lists of dicts. chart.to(data=df2) animates the change: bars grow, move, enter and leave by key; the value axis follows.

Parameters:

Name Type Default Description
data DataTable required chart.to(data=df2) animates the change: bars grow, move, enter and leave by key; the value axis follows.
x str required Bar chart from a table: x= is the category column, y= the value column and key= identifies each bar.
y str required Bar chart from a table: x= is the category column, y= the value column and key= identifies each bar.
key str | None None Bar chart from a table: x= is the category column, y= the value column and key= identifies each bar.
width float 8.0
height float 4.5
color ColorLike | Mapping[str, ColorLike] | None None
labels bool True
grid bool False
bar_ratio float 0.7
label_size float 0.28
**props Unpack[ChartKeywords] variadic Keyword arguments (ChartKeywords): rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, name: str | None.

Props (animatable with .to(), settable with .set() or in the constructor):

Prop Kind Default Interpolation
y_max float 1.0 linear

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

@k.scene
def energy(s: k.Scene):
    chart = k.BarChart({"country": ["PT", "ES"], "gwh": [50, 260]}, x="country", y="gwh").place(at="center")
    s.play(k.draw(chart))
    s.play(chart.to(data={"country": ["ES", "PT", "FR"], "gwh": [300, 80, 540]}), duration=2)

See also: k.LineChart, k.Table, k.Bar.

Members:

  • keys: Keys of the bars, in slot order (as of the last scheduled transition).
  • bar: The bar of key.
  • enter: k.draw(chart): axes are drawn, then the bars grow from the baseline.
  • to: chart.to(data=df2): animated change of data (plus any other props).

Inherited from k.Group: children, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.BarChart.keys (property)

barchart.keys: list[str]  # read-only

Keys of the bars, in slot order (as of the last scheduled transition).

k.BarChart.bar (method)

barchart.bar(key: object) -> ChartBar

The bar of key.

Parameters:

Name Type Default Description
key object required The bar of key.

k.BarChart.enter (method)

barchart.enter() -> Animation

k.draw(chart): axes are drawn, then the bars grow from the baseline.

k.BarChart.to (method)

barchart.to(*, data: DataTable | None = None, **kw: Unpack[ChangeKeywords]) -> Animation

chart.to(data=df2): animated change of data (plus any other props).

Parameters:

Name Type Default Description
data DataTable | None None chart.to(data=df2): animated change of data (plus any other props).
**kw Unpack[ChangeKeywords] variadic

k.PieChart (class)

k.PieChart(
    data: DataTable,
    labels: str,
    values: str,
    *,
    key: str | None = None,
    radius: float = 2.0,
    donut: float = 0.0,
    color: ColorLike | Mapping[str, ColorLike] | None = None,
    percent: bool = True,
    label_size: float = 0.26,
    **props: Unpack[ChartKeywords],
)

One slice per row of a table: labels= names the category column and values= the numbers; donut=0.5 leaves a hole (a fraction of radius=). Slices start at the top and go clockwise, labelled outside with their percentage (narrow ones get a leader line). pie.to(data=df2) animates the shares; new keys grow in, missing ones shrink away. pie.slice("IT") is a slice (.sector, .label, .percent).

Parameters:

Name Type Default Description
data DataTable required pie.to(data=df2) animates the shares; new keys grow in, missing ones shrink away.
labels str required One slice per row of a table: labels= names the category column and values= the numbers; donut=0.5 leaves a hole (a fraction of radius=).
values str required One slice per row of a table: labels= names the category column and values= the numbers; donut=0.5 leaves a hole (a fraction of radius=).
key str | None None
radius float 2.0 One slice per row of a table: labels= names the category column and values= the numbers; donut=0.5 leaves a hole (a fraction of radius=).
donut float 0.0 One slice per row of a table: labels= names the category column and values= the numbers; donut=0.5 leaves a hole (a fraction of radius=).
color ColorLike | Mapping[str, ColorLike] | None None
percent bool True
label_size float 0.26
**props Unpack[ChartKeywords] variadic Keyword arguments (ChartKeywords): rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis, name: str | None.

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

MIX = {"source": ["Solar", "Wind", "Hydro", "Gas"], "twh": [10, 25, 30, 35]}
LATER = {"source": ["Solar", "Wind", "Hydro", "Gas"], "twh": [35, 30, 25, 10]}

@k.scene
def mix(s: k.Scene):
    pie = k.PieChart(MIX, labels="source", values="twh", donut=0.45).place(at="center")
    s.play(k.draw(pie))
    s.play(pie.to(data=LATER), duration=2)
    s.play(k.indicate(pie.slice("Solar")))

See also: k.BarChart, k.Sector.

Members:

  • keys: Keys of the slices, in order (as of the last scheduled transition).
  • slice: The slice of key.
  • enter: k.draw(pie): the slices are drawn one after the other, then their labels appear.
  • to: pie.to(data=df2): animated change of data (plus any other props).

Inherited from k.Group: children, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.PieChart.keys (property)

piechart.keys: list[str]  # read-only

Keys of the slices, in order (as of the last scheduled transition).

k.PieChart.slice (method)

piechart.slice(key: object) -> PieSlice

The slice of key.

Parameters:

Name Type Default Description
key object required The slice of key.

k.PieChart.enter (method)

piechart.enter() -> Animation

k.draw(pie): the slices are drawn one after the other, then their labels appear.

k.PieChart.to (method)

piechart.to(*, data: DataTable | None = None, **kw: Unpack[ChangeKeywords]) -> Animation

pie.to(data=df2): animated change of data (plus any other props).

Parameters:

Name Type Default Description
data DataTable | None None pie.to(data=df2): animated change of data (plus any other props).
**kw Unpack[ChangeKeywords] variadic

k.LineChart (class)

k.LineChart(
    data: DataTable,
    x: str,
    y: str | Sequence[str],
    *,
    x_range: Sequence[float] | None = None,
    y_range: Sequence[float] | None = None,
    width: float = 8.0,
    height: float = 4.5,
    colors: Sequence[ColorLike] | None = None,
    dots: bool = False,
    legend: bool = True,
    **props: Unpack[UnplacedKeywords],
)

A k.Axes with one line per y= column (one or several), connecting the table's points in x= order. chart.to(data=df2) morphs the lines point by point; the axis ranges stay fixed (use y_range= to cover all the data).

Parameters:

Name Type Default Description
data DataTable required chart.to(data=df2) morphs the lines point by point; the axis ranges stay fixed (use y_range= to cover all the data).
x str required A k.Axes with one line per y= column (one or several), connecting the table's points in x= order.
y str | Sequence[str] required A k.Axes with one line per y= column (one or several), connecting the table's points in x= order.
x_range Sequence[float] | None None chart.to(data=df2) morphs the lines; the axes ranges stay fixed (pass x_range=/y_range= covering every dataset you will show).
y_range Sequence[float] | None None chart.to(data=df2) morphs the lines point by point; the axis ranges stay fixed (use y_range= to cover all the data).
width float 8.0
height float 4.5
colors Sequence[ColorLike] | None None
dots bool False
legend bool True
**props Unpack[UnplacedKeywords] variadic Keyword arguments (UnplacedKeywords): name: str | None, key: str | None, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis.

Props inherited from k.Axes: x_range, y_range, size.

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

@k.scene
def lines(s: k.Scene):
    chart = k.LineChart({"h": [0, 12, 24], "kw": [0, 6, 0]}, x="h", y="kw", y_range=(0, 8)).place(at="center")
    s.play(k.draw(chart))
    s.play(chart.to(data={"h": [0, 6, 12, 18, 24], "kw": [0, 3, 7, 3, 0]}), duration=2)

See also: k.Axes, k.BarChart.

Members:

  • to: chart.to(data=df2): the lines morph to the new values (plus any other props).

Inherited from k.Axes: map_x, map_y, local_point, point, add, origin, in_view, plot, dot, area, segment, hband, vband, vector, vline, hline, scatter, parametric, bars, zoom_to. Inherited from k.Group: children, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.LineChart.to (method)

linechart.to(
    *,
    data: DataTable | None = None,
    **kw: Unpack[ChangeKeywords],
) -> Animation

chart.to(data=df2): the lines morph to the new values (plus any other props).

Parameters:

Name Type Default Description
data DataTable | None None chart.to(data=df2): the lines morph to the new values (plus any other props).
**kw Unpack[ChangeKeywords] variadic

k.Table (class)

k.Table(
    data: DataTable,
    columns: Sequence[str] | None = None,
    *,
    size: float = 0.32,
    header_color: ColorLike | None = None,
    rule: bool = True,
    widths: Sequence[float | None] | None = None,
    reserve: Sequence[DataTable] = (),
    **props: Unpack[TransformKeywords],
)

Table of k.Text with a highlighted header; columns= selects and orders the columns. table.to(data=df2) updates the cells: changed texts flash with the new value, new rows appear and removed ones leave. table.cells[r][c] are the cells. Columns fit their text; reserve=[df2] sizes them for data shown later (they keep their width as rows arrive) and widths= sets minimum widths per column.

Parameters:

Name Type Default Description
data DataTable required table.to(data=df2) updates the cells: changed texts flash with the new value, new rows appear and removed ones leave.
columns Sequence[str] | None None Table of k.Text with a highlighted header; columns= selects and orders the columns.
size float 0.32 k.Table(df, columns=["pais", "gwh"], size=0.32).
header_color ColorLike | None None
rule bool True
widths Sequence[float | None] | None None Columns fit their text; reserve=[df2] sizes them for data shown later (they keep their width as rows arrive) and widths= sets minimum widths per column.
reserve Sequence[DataTable] () Columns fit their text; reserve=[df2] sizes them for data shown later (they keep their width as rows arrive) and widths= sets minimum widths per column.
**props Unpack[TransformKeywords] variadic Keyword arguments (TransformKeywords): name: str | None, key: str | None, x: FloatVal, y: FloatVal, position: VecVal, rotate: FloatVal, anchor: VecVal, z: FloatVal, scale: FloatVal, scale_x: FloatVal, scale_y: FloatVal, opacity: FloatVal, visible: BoolVal, bleed: BoolVal, emphasis: Emphasis.

Props inherited from k.Node: x, y, rotate, scale, scale_x, scale_y, anchor, opacity, z, visible, bleed, emphasis.

Example:

@k.scene
def table(s: k.Scene):
    t = k.Table({"country": ["PT", "ES"], "gwh": [50, 260]}).place(at="center")
    s.play(k.fade_in(t))
    s.play(t.to(data={"country": ["PT", "ES", "FR"], "gwh": [80, 260, 1200]}))

See also: k.BarChart, k.Text.

Members:

  • to: table.to(data=df2): animated update of the cells (plus any other props).

Inherited from k.Group: children, swap, insert, pop, fit. Inherited from k.Node: set, unbind, edge, age, entered, exited, copy, place, to_place, unpin.

k.Table.to (method)

table.to(*, data: DataTable | None = None, **kw: Unpack[ChangeKeywords]) -> Animation

table.to(data=df2): animated update of the cells (plus any other props).

Parameters:

Name Type Default Description
data DataTable | None None table.to(data=df2): animated update of the cells (plus any other props).
**kw Unpack[ChangeKeywords] variadic