Skip to main content

Hexalate

A Python library for generating hexagonal tessellations with support for axial coordinates, colormap plotting, GeoJSON export, and more.

Installation

pip install hexalate

Quick Start

import hexalate as hx

grid = hx.HexGrid(width=10, height=8, hex_size=0.5)
grid.plot()

HexGrid

The main class. Creates a grid that fills a rectangular area.

grid = hx.HexGrid(
    width=10,
    height=8,
    hex_size=0.5,
    orientation="pointy",   # "pointy" (default) or "flat" top
)

Orientation

pointy = hx.HexGrid(10, 8, 0.5, orientation="pointy")  # ⬡ pointy top (default)
flat   = hx.HexGrid(10, 8, 0.5, orientation="flat")    # ⬡ flat top

Iterating and accessing hexagons

for h in grid:
    print(h.x, h.y, h.q, h.r)   # Cartesian center + axial coords

# Access by axial coordinates
h = grid.get(q=0, r=0)

# Get all 6 existing neighbors
neighbors = grid.neighbors(q=0, r=0)

Hexagon properties

Each Hexagon dataclass exposes:

Attribute Type Description
x, y float Cartesian center
q, r int Axial coordinates
s int Third cube coordinate (-q - r)
coords list 7 (x, y) vertex tuples
h = grid.get(2, 3)
print(h.s)                       # cube coordinate
print(h.distance_to(grid.get(0, 0)))  # hex distance
print(h.neighbor_coords())       # list of (q, r) neighbor positions

Plotting

# Basic
grid.plot()

# With a colormap driven by per-hex values
import random
values = [random.random() for _ in grid]
grid.plot(values=values, colormap="plasma")

# Save to file instead of showing
grid.plot(output="grid.png", dpi=200)
grid.plot(values=values, colormap="viridis", output="heatmap.svg")

# Convenience shortcut
grid.save_to_file("grid.png", dpi=150)

Export

# Pandas DataFrame (requires pandas)
df = grid.to_dataframe()
# columns: x, y, q, r

# GeoJSON
geojson = grid.to_geojson()   # dict
grid.save_geojson("grid.geojson")

# Backward-compatible list of dicts
data = grid.to_list()
# keys: x, y, q, r, coords

Module-level functions (v0.1 / v0.2 compatible)

The original API still works:

tessellation = hx.create_hexagonal_tessellation(width=10, height=5, hex_size=0.5)
hx.plot_hexagonal_tessellation(tessellation)

# With colormap
import random
values = [random.random() for _ in tessellation]
hx.plot_hexagonal_tessellation(tessellation, colormap="coolwarm", values=values)

# Save to file
hx.plot_hexagonal_tessellation(tessellation, output="grid.png")

Single hexagon

vertices = hx.hexagon(x_center=0.0, y_center=0.0, size=1.0)              # pointy
vertices = hx.hexagon(x_center=0.0, y_center=0.0, size=1.0, orientation="flat")

Returns a list of 7 (x, y) tuples (closed polygon).

Command Line

# Display
hexalate --width 10 --height 8 --size 0.5

# Flat-top orientation
hexalate --width 10 --height 8 --size 0.5 --orientation flat

# Random colormap coloring
hexalate --width 10 --height 8 --size 0.5 --colormap plasma

# Save to file
hexalate --width 10 --height 8 --size 0.5 --output grid.png
hexalate --width 10 --height 8 --size 0.5 --colormap viridis --output heatmap.svg

License

MIT License.

Metadata

Release files for hexalate 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hexalate 0.3.0
File Size Uploaded
hexalate-0.3.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hexalate 0.3.0
File Interpreter ABI Platform
hexalate-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.8 kB

Release files / hexalate-0.3.0.tar.gz

Download URL hexalate-0.3.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0acbf555692d6d544bfaf38800abb8468dd9e2a6ae001783b6e4c10e05110f2a
BLAKE2b-256 checksum
How to use checksums
686d9c4f5319b61ad122ae6d4c0eb2f5774f29a59efe6e2df119964bef601be1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / hexalate-0.3.0-py3-none-any.whl

Download URL hexalate-0.3.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c452eb80f01d5319dc623f5870c140dfae615889e68746f520b5d12ed23359b1
BLAKE2b-256 checksum
How to use checksums
794a797064005d83aa5ce006c9b4bc1965342a3d662964c06218b4bf33d4b425
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page