Plotting¶
Every plotting function returns a standard Matplotlib Figure. It draws immediately,
without opening a window or closing the figure. Use fig.savefig(...), plt.show(),
and plt.close(fig) as needed. ax= places the drawing on your own axes.
- hilbertplot.plot(data, *, curve=0, fourier=False, difference=False, granularity=1, cmap='viridis', fit='pad', order=None, colorbar=True, ax=None, **style)¶
Plot a real one-dimensional sequence along a selected curve.
- Parameters:
data (array_like, shape (N,)) – Nonempty real numeric sequence. NaNs and masked samples mark missing values; infinities and complex values are rejected. Values are copied to floating point for display, so large integers may lose precision.
curve (int or str, default 0) – Curve index in 0..39, friendly label (for example, “Moore”), or paper symbol (for example, “12H”). The default is the standard Hilbert curve.
fourier (bool, default False) – Render the centred 2-D Fourier magnitude of the mapped image. Incompatible with difference=True. Accepts integer 0 or 1.
difference (bool, default False) – Render mean 8-neighbour visit-index distances for the complete grid. This is a property of curve geometry, independent of data values. Incompatible with fourier=True. Accepts integer 0 or 1.
granularity (int, default 1) – Positive block length. Replace consecutive blocks with their means, repeated to preserve sequence length. A final short block uses its own mean. One leaves samples unchanged; averaging is lossy.
cmap (str, matplotlib.colors.Colormap or sequence of colors, default 'viridis') – Matplotlib colormap, or color stops interpolated into one continuous gradient (for example, [‘#132b43’, ‘white’, ‘#c44e52’]).
fit ({'pad', 'square', 'truncate', 'auto'}, default 'pad') – ‘pad’ uses the smallest enclosing power-of-two square. ‘square’ uses a side of ceil(sqrt(N)) and requires a generalizing curve. ‘truncate’ uses the largest power-of-two square fitting inside the sequence and discards the tail. ‘auto’ chooses ‘square’ when supported, else ‘pad’.
order (int or None, optional) – Fix the grid side to 2**order, with order >= 0. Without an explicit order, use fit to determine the size. Too much data raises unless fit=’truncate’.
colorbar (bool, default True) – Attach a color scale to the drawing.
ax (matplotlib.axes.Axes or None, optional) – Draw on these axes; otherwise create a new figure and axes.
**style (dict, optional) – Drawing keywords: title (str), vmin/vmax (float color limits), fill (padding value, default NaN), and Matplotlib imshow properties such as norm, alpha and interpolation. Fourier keywords are window (Hann, default False), log (log1p magnitude, default True), and remove_dc (subtract the image mean, default True).
- Returns:
fig – Figure containing the drawing. Call fig.savefig(…) to export, matplotlib.pyplot.show() to display, or pyplot.close(fig) to release it.
- Return type:
matplotlib.figure.Figure
- Raises:
TypeError – Nonreal/non-numeric input, invalid boolean flags, or unknown keywords.
ValueError – Empty/non-1-D data, infinity, incompatible transformations, unsupported fitting, insufficient grid capacity, or a request over the cell limit.
See also
hilbertplot.plot_curveDraw the path itself.
hilbertplot.data.to_gridConvert values without display normalization.
hilbertplot.data.fourierCompute a spectrum without plotting.
Notes
Each call draws one image and does not open a window. NaNs are transparent in the data image. Fourier color limits default to the 50th and 99.8th percentiles; this affects display only. Use data.to_grid for lossless numeric conversion and data.fourier to obtain the transformed array.
Examples
>>> import hilbertplot as hp >>> fig = hp.plot([1, 2, 3, 4], curve="Moore") >>> fig = hp.plot(range(100), fourier=True)
- hilbertplot.plot_curve(curve=0, order=None, *, shape=None, ax=None, mode='auto', color=None, cmap='viridis', linewidth=None, endpoints=True, title=None)¶
Draw a curve path on a square or quasisquare.
- Parameters:
curve (int or str, default 0) – Curve index in 0..39, friendly label (for example, “Moore”), or paper symbol (for example, “12H”). The default is the standard Hilbert curve.
order (int or None, optional) – Nonnegative recursion depth; the side is 2**order. Defaults to 4 when neither order nor shape is supplied. Mutually exclusive with shape.
shape (tuple of int or None, optional) – Explicit (rows, columns) of a supported square or quasisquare. Arbitrary sizes require one of curves 0, 3, 4, 5, 24, 29, 30, 31. The orientation is chosen to keep the quasisquare path connected.
ax (matplotlib.axes.Axes or None, optional) – Draw on these axes, or create a new figure.
mode ({'auto', 'line', 'fill'}, default 'auto') – Draw connected segments, or color cells by visit order. Auto uses lines below effective order 8 and filled cells otherwise.
color (color-like or None, optional) – Solid line color. With None, color the path using cmap.
cmap (str or matplotlib.colors.Colormap, default 'viridis') – Color path segments or filled cells by visit order.
linewidth (float or None, optional) – Line width in points; None selects a width for the grid size.
endpoints (bool, default True) – Mark the entry with a circle and exit with a square in line mode.
title (str or None, optional) – Axes title; None uses the curve label and grid size.
- Returns:
fig – Figure containing the drawing. Call fig.savefig(…) to export, matplotlib.pyplot.show() to display, or pyplot.close(fig) to release it.
- Return type:
matplotlib.figure.Figure
- Raises:
ValueError – Both order and shape are given, shape is unsupported, mode is invalid, or the requested allocation exceeds the cell limit.
See also
hilbertplot.curves.pointsGet power-of-two path coordinates.
hilbertplot.curves.gridGet arbitrary square/quasisquare coordinates.
Examples
>>> import hilbertplot as hp >>> fig = hp.plot_curve(0, order=3) >>> fig = hp.plot_curve(3, shape=(15, 16), mode="line")
- hilbertplot.gallery(curves=None, order=3, *, ncols=None, mode='auto', cmap='viridis', color=None, title=None)¶
Draw a gallery of selected curves and return a Matplotlib figure.
- Parameters:
curves (iterable of int, str or dict, optional) – Indices, labels, symbols or metadata dictionaries from curves.catalog or a group function. None selects all forty curves.
order (int, default 3) – Nonnegative recursion depth for every curve.
ncols (int or None, optional) – Number of columns. None chooses a layout for the number of curves.
mode ({'auto', 'line', 'fill'}, default 'auto') – Path segments or cells colored by visit order; see plot_curve.
cmap (str or matplotlib.colors.Colormap, default 'viridis') – Color path segments or cells by visit order.
color (color-like or None, optional) – Solid line color; None uses cmap.
title (str or None, optional) – Optional title for the whole figure.
- Returns:
fig – Figure containing the drawing. Call fig.savefig(…) to export, matplotlib.pyplot.show() to display, or pyplot.close(fig) to release it.
- Return type:
matplotlib.figure.Figure
See also
hilbertplot.plot_curveDraw one curve with more styling options.
Examples
>>> import hilbertplot as hp >>> fig = hp.gallery(hp.curves.generalizing(), order=3)