carto_flow.symbol_cartogram.tiling¶
Tiling abstractions for tile-based symbol cartograms.
This module defines the Tiling ABC and concrete tiling classes that generate
congruent tilings of the plane. Each tiling produces a TilingResult containing
tile polygons, per-tile transforms, and a precomputed adjacency matrix.
Tiling Classes
SquareTiling Regular square grid. HexagonTiling Regular hexagonal grid (pointy-top). TriangleTiling Tiling by congruent triangles (any triangle tiles the plane). QuadrilateralTiling Tiling by congruent quadrilaterals (any simple quadrilateral tiles the plane).
Classes:
-
HexagonTiling–Regular hexagonal grid tiling (pointy-top orientation).
-
IsohedralTiling–Isohedral tiling based on the Grünbaum-Shephard classification.
-
QuadrilateralTiling–Tiling by congruent quadrilaterals.
-
SquareTiling–Regular square grid tiling.
-
TileAdjacencyType–How tile adjacency is determined.
-
TileTransform–Transform for a single tile: center position, rotation, and flip.
-
Tiling–A congruent tiling of the plane.
-
TilingResult–Output of tiling generation.
-
TriangleTiling–Tiling by congruent triangles.
Functions:
-
resolve_tiling–Resolve a tiling specification to a Tiling instance.
HexagonTiling
¶
Bases: Tiling
Regular hexagonal grid tiling (pointy-top orientation).
Parameters:
-
pointy_top(bool, default:True) –If True (default), hexagons have a vertex at top.
Methods:
-
canonical_symbol–Return a HexagonSymbol matching this tiling's orientation.
-
from_polygon–Create from polygon (must be a hexagon; ignored for HexagonTiling).
-
tile_size_for_symbol_size–Compute tile_size for hexagon tiling.
Attributes:
-
canonical_tile(Polygon) –Unit hexagon centered at origin.
canonical_symbol
¶
Return a HexagonSymbol matching this tiling's orientation.
from_polygon
classmethod
¶
Create from polygon (must be a hexagon; ignored for HexagonTiling).
tile_size_for_symbol_size
¶
Compute tile_size for hexagon tiling.
For HexagonTiling, tile_size is the circumradius (center to vertex). HexagonSymbol has bounding_radius = 0.5, so after scaling by 2*size, the circumradius equals symbol_size.
Therefore: tile_size = symbol_size * (1 + spacing)
IsohedralTiling
¶
IsohedralTiling(
tiling_type: int,
parameters: list[float] | None = None,
edge_curves: dict[int, list[tuple[float, float]]]
| None = None,
edge_curve_modes: dict[int, str] | None = None,
)
Bases: Tiling
Isohedral tiling based on the Grünbaum-Shephard classification.
Wraps the tactile library to generate any of 81 isohedral tiling types.
Each type has 0-6 free parameters controlling tile vertex positions, and
supports optional custom edge curves for Escher-style tiles.
Parameters:
-
tiling_type(int) –Isohedral type number (IH1-IH93, with some gaps). Use
IsohedralTiling.available_types()for the full list. -
parameters(list[float], default:None) –Free parameters for the tiling type. If
None, uses defaults. -
edge_curves(dict[int, list[tuple[float, float]]], default:None) –Custom edge curves keyed by edge shape ID. Each curve is a list of
(x, y)points in canonical space from(0, 0)to(1, 0). Symmetry constraints (S, U) are enforced automatically. Edge shape IDs and types can be inspected viatype_info(). IfNone, all edges are straight lines.
Methods:
-
available_types–Return list of valid isohedral tiling type numbers.
-
canonical_symbol–Return an IsohedralTileSymbol with this tiling's parameters and curves.
-
describe–Return a human-readable summary of an isohedral tiling type.
-
find_types–Find isohedral tiling types matching the given criteria.
-
from_dict–Load a tiling from a serialized dictionary.
-
from_polygon–Not supported — use
IsohedralTiling(tiling_type, parameters). -
from_preset–Create an IsohedralTiling from a named preset.
-
list_presets–Return a dict mapping preset names to their descriptions.
-
load–Load a tiling configuration from a JSON file.
-
plot_prototile–Plot the prototile with labeled, color-coded edges.
-
save–Save the tiling configuration to a JSON file.
-
tile_size_for_symbol_size–Compute tile_size for isohedral tiling.
-
to_dict–Serialize the tiling configuration to a dictionary.
-
type_info–Return metadata for an isohedral tiling type.
Attributes:
-
canonical_tile(Polygon) –Unit-area prototile centered at origin.
available_types
staticmethod
¶
Return list of valid isohedral tiling type numbers.
canonical_symbol
¶
Return an IsohedralTileSymbol with this tiling's parameters and curves.
describe
¶
Return a human-readable summary of an isohedral tiling type.
Can be called on an instance (t.describe()) or on the class
(IsohedralTiling.describe(83)).
Parameters:
-
tiling_type(int, default:None) –Isohedral type number. Not needed when called on an instance.
Returns:
-
str–Multi-line description of the tiling type.
find_types
staticmethod
¶
find_types(
*,
num_vertices: int | None = None,
num_parameters: int | None = None,
max_parameters: int | None = None,
num_aspects: int | None = None,
has_reflections: bool | None = None,
edge_types: set[str] | None = None,
all_edges: str | None = None,
has_customizable_edges: bool | None = None,
) -> list[int]
Find isohedral tiling types matching the given criteria.
All arguments are optional filters. Only types satisfying every specified filter are returned.
Parameters:
-
num_vertices(int, default:None) –Exact number of prototile vertices (3, 4, 5, or 6).
-
num_parameters(int, default:None) –Exact number of free parameters.
-
max_parameters(int, default:None) –Maximum number of free parameters.
-
num_aspects(int, default:None) –Exact number of aspects (copies per fundamental domain).
-
has_reflections(bool, default:None) –If
True, only types with reflected aspects. IfFalse, only types without reflections. -
edge_types(set of str, default:None) –Required edge types, e.g.
{"J", "S"}. Only types whose edges include all listed types are returned. -
all_edges(str, default:None) –If set, only types where every edge is this type (e.g.
"J"). -
has_customizable_edges(bool, default:None) –If
True, at least one edge is J, S, or U. IfFalse, all edges are I (straight).
Returns:
-
list[int]–Matching isohedral type numbers, sorted.
Examples:
from_dict
classmethod
¶
Load a tiling from a serialized dictionary.
Parameters:
-
data(dict) –Dictionary as produced by :meth:
to_dict.
Returns:
from_polygon
classmethod
¶
Not supported — use IsohedralTiling(tiling_type, parameters).
from_preset
classmethod
¶
Create an IsohedralTiling from a named preset.
Parameters:
-
name(str) –Preset name. Use
IsohedralTiling.list_presets()for options. -
**kwargs–Overrides passed to
IsohedralTiling(), e.g.edge_curves,parameters.
Returns:
list_presets
classmethod
¶
Return a dict mapping preset names to their descriptions.
Returns:
-
dict[str, str]–
load
classmethod
¶
Load a tiling configuration from a JSON file.
Parameters:
-
path(str or Path) –Path to a JSON file previously written by :meth:
save.
Returns:
plot_prototile
¶
Plot the prototile with labeled, color-coded edges.
Parameters:
-
ax(Axes, default:None) –Axes to draw on. If
None, a new figure is created. -
show_labels(bool, default:True) –Whether to annotate edges with their ID and type.
Returns:
-
Axes–
save
¶
Save the tiling configuration to a JSON file.
Parameters:
-
path(str or Path) –Destination file path. The file is created or overwritten.
tile_size_for_symbol_size
¶
Compute tile_size for isohedral tiling.
IsohedralTiling uses unit-area tiles. TileSymbol normalizes to bounding_radius = 0.5, so we need to compute the original tile's bounding radius to find the correct scale factor.
to_dict
¶
Serialize the tiling configuration to a dictionary.
Returns:
-
dict–Dictionary with keys
tiling_type,parameters, andedge_curvessuitable for passing to :meth:from_dictor saving as JSON.
type_info
¶
Return metadata for an isohedral tiling type.
Can be called on an instance (t.type_info()) or on the class
(IsohedralTiling.type_info(83)).
Parameters:
-
tiling_type(int, default:None) –Isohedral type number. Not needed when called on an instance.
Returns:
-
dict–Keys include
num_parameters,num_vertices,num_aspects,num_edge_shapes,edge_shapes,default_parameters,edges,has_reflections,customizable_shape_ids,parameters.The
edgeslist has one entry per prototile edge with keys:edge_index,shape_id,shape_type,description,customizable.
QuadrilateralTiling
¶
Bases: Tiling
Tiling by congruent quadrilaterals.
Any simple quadrilateral tiles the Euclidean plane via 180° rotation about edge midpoints.
Parameters:
-
tile(Polygon) –A quadrilateral (4-vertex polygon). Will be normalized to unit area internally. The shape (angles/proportions) is preserved.
Methods:
-
canonical_symbol–Return a TileSymbol wrapping this quadrilateral's canonical tile.
-
from_polygon–Create a tiling from a user-supplied quadrilateral.
-
parallelogram–Parallelogram with given angle and aspect ratio.
-
rectangle–Rectangle with given aspect ratio (height/width).
-
rhombus–Rhombus (all sides equal) with given angle.
-
tile_size_for_symbol_size–Compute tile_size for quadrilateral tiling.
-
trapezoid–Isosceles trapezoid.
Attributes:
-
canonical_tile(Polygon) –Unit-area quadrilateral centered at origin.
canonical_symbol
¶
Return a TileSymbol wrapping this quadrilateral's canonical tile.
from_polygon
classmethod
¶
Create a tiling from a user-supplied quadrilateral.
parallelogram
classmethod
¶
Parallelogram with given angle and aspect ratio.
Parameters:
-
angle(float, default:60.0) –Interior angle in degrees (0 < angle < 180).
-
aspect_ratio(float, default:1.0) –Ratio of side b to side a.
rectangle
classmethod
¶
Rectangle with given aspect ratio (height/width).
Parameters:
-
aspect_ratio(float, default:1.0) –Ratio of height to width. Default 1.0 gives a square.
rhombus
classmethod
¶
Rhombus (all sides equal) with given angle.
Parameters:
-
angle(float, default:60.0) –Interior angle in degrees.
tile_size_for_symbol_size
¶
Compute tile_size for quadrilateral tiling.
QuadrilateralTiling uses unit-area tiles. TileSymbol normalizes to bounding_radius = 0.5, so we need to compute the original tile's bounding radius to find the correct scale factor.
trapezoid
classmethod
¶
Isosceles trapezoid.
Parameters:
-
top_ratio(float, default:0.5) –Ratio of top edge to bottom edge. Must be < 1.
-
height(float, default:1.0) –Height of the trapezoid.
SquareTiling
¶
Bases: Tiling
Regular square grid tiling.
All tiles are axis-aligned squares of equal size.
Methods:
-
canonical_symbol–Return a SquareSymbol for this tiling.
-
from_polygon–Create from polygon (must be a square; ignored for SquareTiling).
Attributes:
-
canonical_tile(Polygon) –Unit square centered at origin.
from_polygon
classmethod
¶
Create from polygon (must be a square; ignored for SquareTiling).
TileAdjacencyType
¶
Bases: str, Enum
How tile adjacency is determined.
TileTransform
dataclass
¶
Transform for a single tile: center position, rotation, and flip.
Attributes:
-
center(tuple[float, float]) –Tile center in world coordinates.
-
rotation(float) –Rotation angle in degrees (counter-clockwise).
-
flipped(bool) –Whether the tile is reflected about the vertical axis (before rotation).
Tiling
¶
Bases: ABC
A congruent tiling of the plane.
Subclasses implement specific tiling patterns. The generate method
produces tiles covering a bounding box.
Methods:
-
canonical_symbol–Return the Symbol matching this tiling's tile shape.
-
from_polygon–Create a tiling from a user-supplied polygon.
-
generate–Generate tiles covering the bounding box.
-
plot_tile–Plot the canonical (proto)tile shape using matplotlib.
-
tile_size_for_symbol_size–Compute tile_size so that a symbol of given size fills the tile.
Attributes:
-
canonical_tile(Polygon) –The tile shape at unit size, centered at origin.
canonical_tile
abstractmethod
property
¶
The tile shape at unit size, centered at origin.
canonical_symbol
abstractmethod
¶
Return the Symbol matching this tiling's tile shape.
Returns:
-
Symbol–A symbol instance that can render tiles from this tiling.
from_polygon
abstractmethod
classmethod
¶
Create a tiling from a user-supplied polygon.
generate
abstractmethod
¶
generate(
bounds: tuple[
float, float, float, float
] = DEFAULT_BOUNDS,
n_tiles: int | None = None,
tile_size: float | None = None,
margin: float = 0.1,
adjacency_type: TileAdjacencyType = TileAdjacencyType.EDGE,
) -> TilingResult
Generate tiles covering the bounding box.
Parameters:
-
bounds(tuple, default:DEFAULT_BOUNDS) –Bounding box as (minx, miny, maxx, maxy). Defaults to the unit box
(-1, -1, 1, 1)(see :data:DEFAULT_BOUNDS). -
n_tiles(int, default:None) –Approximate number of tiles. Mutually exclusive with tile_size. When neither is given, defaults to :data:
DEFAULT_N_TILES. -
tile_size(float, default:None) –Size of each tile. Mutually exclusive with n_tiles.
-
margin(float, default:0.1) –Fractional margin around bounding box.
-
adjacency_type(TileAdjacencyType, default:EDGE) –Whether adjacency requires shared edges or just shared vertices.
Returns:
plot_tile
¶
plot_tile(
ax=None,
*,
face_color: str | None = None,
edge_color: str = "#1971c2",
alpha: float = 0.7,
show_vertices: bool = True,
show_vertex_labels: bool = False,
linewidth: float = 1.5,
)
Plot the canonical (proto)tile shape using matplotlib.
No call to :meth:generate is needed — the tile is derived directly
from the tiling's :attr:canonical_tile property.
Parameters:
-
ax(Axes, default:None) –Axes to draw on. A new figure is created if ax is
None. -
face_color(str, default:None) –Fill colour. When
Nonethe colour is chosen automatically by vertex count to match the panel UI palette (3 → pink, 4 → blue, 5 → yellow, 6 → green). -
edge_color(str, default:'#1971c2') –Outline colour.
-
alpha(float, default:0.7) –Fill transparency.
-
show_vertices(bool, default:True) –Draw a dot at each tile vertex.
-
show_vertex_labels(bool, default:False) –Annotate each vertex with its 0-based index.
-
linewidth(float, default:1.5) –Outline width in points.
Returns:
-
PrototilePlotResult–Named result with
ax,fig,tile(the patch), andvertices(scatter artist, orNone).
tile_size_for_symbol_size
¶
Compute tile_size so that a symbol of given size fills the tile.
The symbol is defined in the unit square [-0.5, 0.5]² and scaled by
2 * symbol_size. This method computes the appropriate tile_size
parameter for the tiling's generate() method so that the tile matches
the scaled symbol.
Parameters:
-
symbol_size(float) –The native half-extent of the symbol (after area_factor conversion).
-
spacing(float, default:0.0) –Additional spacing as a fraction of symbol size (default 0.0).
Returns:
-
float–The tile_size parameter to pass to generate().
Notes
Different tilings interpret tile_size differently: - SquareTiling: tile_size = side length - HexagonTiling: tile_size = circumradius (center to vertex) - TriangleTiling: tile_size = scale factor for unit-area tile
TilingResult
dataclass
¶
TilingResult(
polygons: list[Polygon],
transforms: list[TileTransform],
adjacency: NDArray[bool_],
vertex_adjacency: NDArray[bool_] | None,
tile_size: float,
inscribed_radius: float,
canonical_tile: Polygon,
n_base_vertices: int | None = None,
)
Output of tiling generation.
Attributes:
-
polygons(list[Polygon]) –Tile polygons in world coordinates.
-
transforms(list[TileTransform]) –Per-tile transforms (center, rotation, flip).
-
adjacency(NDArray[bool_]) –(m, m) boolean edge adjacency matrix between tiles.
-
vertex_adjacency(NDArray[bool_] | None) –(m, m) boolean vertex-only adjacency matrix (tiles sharing exactly one vertex but no edge). None for tilings that don't compute it.
-
tile_size(float) –Size parameter used for generation.
-
inscribed_radius(float) –Radius of the largest circle fitting inside the canonical tile at the generated size.
-
canonical_tile(Polygon) –The unit tile shape (before transforms), at the generated size.
-
n_base_vertices(int or None) –Topological vertex count of the prototile. For most tilings this equals
len(canonical_tile.exterior.coords) - 1, but for isohedral tilings with custom edge curves thecanonical_tilepolygon has many more points due to spline interpolation. Used by :meth:plot_tileto select the correct auto-colour.
Methods:
-
plot–Plot the tiling using matplotlib.
-
plot_tile–Plot the canonical (proto)tile shape using matplotlib.
-
rotate–Rotate all tile positions and orientations.
plot
¶
plot(
ax=None,
*,
color_by: str = "uniform",
face_color: str = "#4e9af1",
edge_color: str = "#333333",
colormap: str = "tab10",
alpha: float = 0.85,
linewidth: float = 0.5,
)
Plot the tiling using matplotlib.
Parameters:
-
ax(Axes, default:None) –Axes to draw on. A new figure is created if ax is
None. -
color_by(('uniform', 'aspect', 'index', 'x', 'y', 'random'), default:"uniform") –Colouring scheme:
"uniform"— all tiles use face_color."aspect"— colour by tile rotation angle (0–360 → colormap)."index"— colour by tile index (0…n−1 → colormap)."x"— colour by tile centroid x coordinate (normalised)."y"— colour by tile centroid y coordinate (normalised)."random"— random colour per tile drawn from colormap.
-
face_color(str, default:'#4e9af1') –Hex fill colour used in
"uniform"mode. -
edge_color(str, default:'#333333') –Stroke colour for tile outlines.
-
colormap(str, default:'tab10') –Matplotlib colormap name used in
"aspect"and"index"modes. -
alpha(float, default:0.85) –Tile fill transparency.
-
linewidth(float, default:0.5) –Tile outline width in points.
Returns:
-
TilingGridPlotResult–Named result with
ax,fig, andtiles(thePolyCollection).
Examples:
plot_tile
¶
plot_tile(
ax=None,
*,
face_color: str | None = None,
edge_color: str = "#1971c2",
alpha: float = 0.7,
show_vertices: bool = True,
show_vertex_labels: bool = False,
linewidth: float = 1.5,
)
Plot the canonical (proto)tile shape using matplotlib.
Parameters:
-
ax(Axes, default:None) –Axes to draw on. A new figure is created if ax is
None. -
face_color(str, default:None) –Fill colour. When
Nonethe colour is chosen automatically by vertex count to match the panel UI palette (3 → pink, 4 → blue, 5 → yellow, 6 → green). -
edge_color(str, default:'#1971c2') –Outline colour.
-
alpha(float, default:0.7) –Fill transparency.
-
show_vertices(bool, default:True) –Draw a dot at each tile vertex.
-
show_vertex_labels(bool, default:False) –Annotate each vertex with its 0-based index.
-
linewidth(float, default:1.5) –Outline width in points.
Returns:
-
PrototilePlotResult–Named result with
ax,fig,tile(the patch), andvertices(scatter artist, orNone).
Examples:
rotate
¶
Rotate all tile positions and orientations.
Returns a new TilingResult with all tile centers rotated about the origin and all tile rotations incremented by the given angle.
Parameters:
-
angle(float) –Rotation angle in degrees (counter-clockwise).
Returns:
-
TilingResult–New TilingResult with rotated tiles.
Notes
The adjacency matrices are preserved since rotation is a rigid transformation that doesn't change neighbor relationships.
TriangleTiling
¶
Bases: Tiling
Tiling by congruent triangles.
Any triangle tiles the Euclidean plane. The tiling is constructed by pairing triangles via 180° rotation about an edge midpoint to form parallelograms, which then tile by translation.
Parameters:
-
tile(Polygon) –A triangle (3-vertex polygon). Will be normalized to unit area internally. The shape (angles/proportions) is preserved.
Methods:
-
canonical_symbol–Return a TileSymbol wrapping this triangle's canonical tile.
-
equilateral–Equilateral triangle tiling.
-
from_polygon–Create a tiling from a user-supplied triangle.
-
isosceles–Isosceles triangle with given apex angle (degrees).
-
right–Right triangle with given aspect ratio (height/base).
-
right_isosceles–Right isosceles triangle tiling (45-45-90).
-
tile_size_for_symbol_size–Compute tile_size for triangle tiling.
Attributes:
-
canonical_tile(Polygon) –Unit-area triangle centered at origin.
canonical_symbol
¶
Return a TileSymbol wrapping this triangle's canonical tile.
from_polygon
classmethod
¶
Create a tiling from a user-supplied triangle.
isosceles
classmethod
¶
Isosceles triangle with given apex angle (degrees).
Parameters:
-
apex_angle(float, default:60.0) –Angle at the apex in degrees. Default 60.0 gives equilateral.
right
classmethod
¶
Right triangle with given aspect ratio (height/base).
Parameters:
-
aspect_ratio(float, default:1.0) –Ratio of height to base. Default 1.0 gives a right isosceles.
right_isosceles
classmethod
¶
Right isosceles triangle tiling (45-45-90).
tile_size_for_symbol_size
¶
Compute tile_size for triangle tiling.
TriangleTiling uses unit-area tiles. TileSymbol normalizes to bounding_radius = 0.5, so we need to compute the original tile's bounding radius to find the correct scale factor.