Recurrence dotplot¶
A text plotted against itself: the sentence × sentence self-similarity grid.
lexograph.presets.recurrence.recurrence_plot(text, *, threshold=0.6, shingle=None, distances=None, mode='binary', figsize=(8.0, 8.0), background='white')
¶
Draw the sentence × sentence recurrence dotplot of a text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The source text. |
required |
threshold
|
float
|
In |
0.6
|
shingle
|
int | None
|
Passed to :func: |
None
|
distances
|
FloatArray | None
|
A precomputed |
None
|
mode
|
RecurrenceMode
|
|
'binary'
|
figsize
|
tuple[float, float]
|
Figure size in inches. |
(8.0, 8.0)
|
background
|
str
|
Figure background colour. |
'white'
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Figure
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the text has fewer than two sentences, or a supplied
|
Contract
- Returns a Figure with exactly one axes.
- The grid is square (sentence count on each axis) and symmetric.
Examples:
>>> from lexograph import load_demo_text
>>> fig = recurrence_plot(load_demo_text())
>>> type(fig).__name__
'Figure'
Source code in lexograph/presets/recurrence.py
lexograph.layout.recurrence.recurrence_distances(units, *, shingle=None)
¶
Return the pairwise Jaccard distance matrix between units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units
|
Sequence[str]
|
The sentences (or any strings) to compare against each other. |
required |
shingle
|
int | None
|
If |
None
|
Returns:
| Type | Description |
|---|---|
FloatArray
|
An |
FloatArray
|
with a zero diagonal. Two units with no features in common are at |
FloatArray
|
distance 1; two empty units are at distance 0. |
Contract
- The matrix is symmetric with a zero diagonal.
- Every entry lies in
[0, 1].
Examples:
>>> d = recurrence_distances(["the cat sat", "the cat sat", "a dog ran"])
>>> float(d[0, 1])
0.0
>>> bool(d[0, 2] > 0.9)
True
Source code in lexograph/layout/recurrence.py
lexograph.layout.recurrence.recurrence_matrix(distances, *, threshold=0.6)
¶
Threshold a distance matrix into a boolean recurrence (dotplot) grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distances
|
FloatArray
|
An |
required |
threshold
|
float
|
Cells with distance |
0.6
|
Returns:
| Type | Description |
|---|---|
ndarray
|
An |
ndarray
|
The diagonal is always |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> d = np.array([[0.0, 0.2, 0.9], [0.2, 0.0, 0.8], [0.9, 0.8, 0.0]])
>>> recurrence_matrix(d, threshold=0.5).tolist()
[[True, True, False], [True, True, False], [False, False, True]]