hilbertplot

Python library · 40 curve constructions

hilbertplot

Plot one-dimensional data along Hilbert curves. Read images as sequences, and reconstruct them along the same path or a different one.

pip install hilbertplot

Python ≥ 3.10PyPIZenodo DOI

HilbertCurve 0
The standard Hilbert path at order four, with its entry and exit marked
Order 4256 cells · one continuous path

Start with your data

Choose a curve by its number, label or paper symbol. Plotting returns Matplotlib figures; conversion returns NumPy arrays.

Plot a sequence

Successive values fill successive cells along the selected curve.

import numpy as np
import hilbertplot as hp

values = np.sin(np.arange(4096) / 37)
fig = hp.plot(values, curve=0, cmap="cividis")
fig.savefig("sequence.png", dpi=180)

Colors, fitting and saving figures →

Read and reconstruct an image

Use the same curve and original shape for an exact round trip.

import numpy as np
import hilbertplot as hp

image = np.arange(256).reshape(16, 16)
sequence = hp.data.from_grid(image, curve=12)
restored = hp.data.to_grid(
    sequence, curve=12, shape=image.shape
)
np.testing.assert_array_equal(restored, image)

Image conversion and reordering →

Analysis examples

A curve sets the arrangement. Fourier and granularity operations make different properties of that arrangement visible. Each example below links to its input, settings and mathematical definition.

The Thue–Morse sequence

The same 1,048,576 binary values appear in both maps. The left map shows their placement along the Hilbert curve; the right shows the centred 2-D Fourier magnitude with a Hann window. Its multiscale spectral structure is easier to identify than in the direct image. This is the spectrum of the mapped image, not the sequence’s 1-D spectrum.

One million Thue-Morse terms mapped along the Hilbert curve
InputThue–Morse · 1024 × 1024 cells
Centred 2-D Fourier magnitude showing multiscale structure
FourierLog magnitude · Hann window

Reproduce the Fourier maps →

Distinguish periodic regions

This sequence interleaves period-4 and period-6 runs, both with mean 1/2. Averaging consecutive blocks of four makes aligned period-4 runs uniform grey, while period-6 runs retain variation. The input length and curve stay the same.

Interleaved period-four and period-six runs before averaging
Input16,384 samples · granularity 1
Uniform period-four regions and varying period-six regions after averaging
Block meansSame samples · granularity 4

Reproduce the granularity maps →

Explore the documentation