Skip to content

Serialization and plotting

Tilings are saved with IsohedralTiling.to_dict, from_dict, save and load; the format is described here.

isotile.io

Serialization of a tiling to a JSON-compatible dict and to JSON files.

The dict has the keys

version "1.1". tiling_type Type number. parameters List of n_params floats. edge_curves Object that maps a shape id (as a string) to the list of [x, y] control points of its curve, with the symmetry of the shape enforced. Absent if the tiling has no curves. edge_curve_modes Object that maps a shape id to "spline" or "linear", for every id in edge_curves. frame [[a, b, c], [d, e, f]], the affine frame. Absent if it is the identity.

Writing is deterministic: the same tiling gives the same dict and the same file, and reading it back gives a tiling with the same type, parameters, curves, modes and frame. Version "1.0" (no modes, no frame) is read, and keys that are not listed are ignored.

isotile.io.to_dict

to_dict(tiling: IsohedralTiling) -> dict[str, Any]

The tiling as a JSON-compatible dict, see the module description for the keys.

isotile.io.from_dict

from_dict(data: Mapping[str, Any]) -> IsohedralTiling

The tiling that to_dict describes.

Raises:

  • ValueError –

    If the version is not 1.x, a required key is missing, a shape id is not an integer, or the content is not a valid tiling (see IsohedralTiling).

isotile.io.save

save(tiling: IsohedralTiling, path: str | Path) -> None

Write the tiling as JSON (UTF-8, indented by 2, ending with a newline); an existing file is overwritten.

isotile.io.load

load(path: str | Path) -> IsohedralTiling

Read a tiling from a JSON file written by save.

Plotting

Needs matplotlib (pip install isotile[plot]).

isotile.plot.plot_prototile

plot_prototile(
    tiling: IsohedralTiling,
    ax: Any = None,
    show_labels: bool = True,
) -> Any

Draw the prototile with its curves.

The outline is filled; with curves, the straight prototile is drawn dashed. With show_labels each edge is labeled with its index and shape (for example "2 J"), and an arrow on the edge shows the direction of the canonical edge (from (0, 0) to (1, 0)), which is against the order of the outline for a reversed edge.

Parameters:

  • tiling (IsohedralTiling) –
  • ax (Axes, default: None ) –

    Axes to draw into; a new figure with equal axis scaling when omitted.

  • show_labels (bool, default: True ) –

Returns:

  • Axes –

Raises:

  • ImportError –

    If matplotlib is not installed.

isotile.plot.plot_tiles

plot_tiles(
    tiles: TileSet, ax: Any = None, color: str = "coloring"
) -> Any

Draw tiles with their curved edges.

Parameters:

  • tiles (TileSet) –
  • ax (Axes, default: None ) –

    Axes to draw into; a new figure with equal axis scaling when omitted.

  • color (str, default: "coloring" ) –

    "coloring" colors the tiles by the coloring of the type (tiles of one color are never adjacent), "aspect" by aspect, anything else is a matplotlib color for all tiles.

Returns:

  • Axes –

Raises:

  • ImportError –

    If matplotlib is not installed.