Render¶
Draw laid-out, encoded units as a matplotlib Figure.
lexograph.render.mpl.render_points(coords, *, channels=None, sizes=None, colors=None, glyphs=None, background='white', figsize=(8.0, 8.0))
¶
Draw one mark per unit at its layout coordinate.
If glyphs are given, each unit is drawn as text; otherwise each unit is a
scatter marker. Channel arrays may be passed individually or bundled in a
:class:~lexograph.encode.channels.Channels; individual arguments win.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
Coords
|
An |
required |
channels
|
Channels | None
|
Resolved channels to use as defaults for |
None
|
sizes
|
ndarray | None
|
Per-unit size in points (marker diameter, or glyph font size). |
None
|
colors
|
list[RGBA] | None
|
Per-unit RGBA colour. |
None
|
glyphs
|
list[str] | None
|
Per-unit text; when given, units are drawn as text not markers. |
None
|
background
|
str
|
Figure and axes background colour. |
'white'
|
figsize
|
tuple[float, float]
|
Figure size in inches. |
(8.0, 8.0)
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Figure
|
class: |
Figure
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Contract
- Returns a Figure with exactly one axes.
- Inputs are never mutated.
Examples:
>>> import numpy as np
>>> fig = render_points(np.array([[0.0, 0.0], [1.0, 1.0]]))
>>> type(fig).__name__
'Figure'
>>> len(fig.axes)
1
Source code in lexograph/render/mpl.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
lexograph.render.mpl.render_path(coords, *, colors=None, color=_DEFAULT_LINE_COLOR, linewidth=1.5, background='white', figsize=(8.0, 8.0))
¶
Draw the units as a connected path through their layout coordinates.
This is the renderer behind the text walk: consecutive units are joined by
line segments. When colors is given (one colour per segment, i.e. one
per unit after the first), the path is drawn as a multi-coloured
:class:~matplotlib.collections.LineCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
Coords
|
An |
required |
colors
|
list[RGBA] | None
|
Per-segment RGBA colours (length |
None
|
color
|
str
|
The path colour when |
_DEFAULT_LINE_COLOR
|
linewidth
|
float
|
Line width in points. |
1.5
|
background
|
str
|
Figure and axes background colour. |
'white'
|
figsize
|
tuple[float, float]
|
Figure size in inches. |
(8.0, 8.0)
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Figure
|
class: |
Figure
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Contract
- Returns a Figure with exactly one axes.
- Inputs are never mutated.
Examples:
>>> import numpy as np
>>> fig = render_path(np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]))
>>> type(fig).__name__
'Figure'
Source code in lexograph/render/mpl.py
lexograph.render.mpl3d.render_path_3d(coords, *, colors=None, color=_DEFAULT_LINE_COLOR, linewidth=1.5, linewidths=None, background='white', figsize=(8.0, 10.0), elev=18.0, azim=-60.0, axes_off=True)
¶
Draw a 3-D path through the layout coordinates as a corkscrew.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
Coords
|
An |
required |
colors
|
list[RGBA] | None
|
Per-segment RGBA colours (length |
None
|
color
|
str
|
The path colour when |
_DEFAULT_LINE_COLOR
|
linewidth
|
float
|
Line width in points, used when |
1.5
|
linewidths
|
Sequence[float] | None
|
Per-segment line widths (length |
None
|
background
|
str
|
Figure and axes background colour. |
'white'
|
figsize
|
tuple[float, float]
|
Figure size in inches. |
(8.0, 10.0)
|
elev
|
float
|
Camera elevation angle in degrees. |
18.0
|
azim
|
float
|
Camera azimuth angle in degrees. |
-60.0
|
axes_off
|
bool
|
Hide the 3-D axes, panes, and ticks for a clean plate. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Figure
|
class: |
Figure
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Contract
- Returns a Figure with exactly one axes.
- Inputs are never mutated.
Examples:
>>> import numpy as np
>>> coords = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 1.0], [1.0, 1.0, 2.0]])
>>> fig = render_path_3d(coords)
>>> type(fig).__name__
'Figure'
Source code in lexograph/render/mpl3d.py
lexograph.render.mpl.frame_axes(ax, coords, *, margin=0.05)
¶
Equalise the aspect ratio, hide the axes, and fit coords with a margin.
A small helper shared by the renderers and presets: it makes an axes show a spatial figure (equal aspect, no ticks or spines) framed to the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The axes to configure. |
required |
coords
|
Coords
|
An |
required |
margin
|
float
|
Fractional padding added around the data extent. |
0.05
|
Examples:
>>> import numpy as np
>>> from matplotlib.figure import Figure
>>> ax = Figure().subplots()
>>> frame_axes(ax, np.array([[0.0, 0.0], [1.0, 1.0]]))
>>> ax.get_aspect()
1.0