spine_score_map¶
The colormap used for SPINE scores, as a plain array.
Pale at score 0 and deep at score 1, monotone in lightness, built from Okabe-Ito anchors so it stays readable in greyscale and to colour-blind readers. The typical bulk recedes and the atypical objects stand out.
spine_data_plot and spine_network_plot apply it for you. Use this
directly only when drawing your own figure; it needs numpy alone.
Syntax¶
from entropy_spine import spine_score_map
help(spine_score_map)
Help on function spine_score_map in module entropy_spine.interface.plots:
spine_score_map(n: 'int' = 256) -> 'np.ndarray'
Sequential colormap for SPINE scores, as an (n, 3) RGB array.
Pale at score 0 and deep at score 1, monotone in lightness, built from
Okabe-Ito anchors so it stays readable in greyscale and to colour-blind
readers. ``spine_data_plot`` and ``spine_network_plot`` apply it for you;
use this directly only when drawing your own figure.
Using it on your own axes¶
Fix the colour limits at 0 to 1, as the package's own figures do, so two pictures can be compared by eye.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap
from entropy_spine import spine, spine_score_map
rng = np.random.default_rng(4242)
D = np.vstack([rng.standard_normal((200, 2)),
[12, 12] + 0.25 * rng.standard_normal((20, 2))])
s, _ = spine(D, "dist2median", "upper")
fig, ax = plt.subplots()
sc = ax.scatter(D[:, 0], D[:, 1], s=30 + 60 * s, c=s,
cmap=ListedColormap(spine_score_map(256)), vmin=0, vmax=1,
edgecolors="0.3", linewidths=0.4)
fig.colorbar(sc, label="score")
ax.set_aspect("equal")
ax.set_title("drawn by hand, coloured by score");
The ramp itself¶
spine_score_map(9).round(3)
array([[0.973, 0.969, 0.882],
[0.958, 0.946, 0.516],
[0.941, 0.894, 0.259],
[0.923, 0.777, 0.084],
[0.902, 0.624, 0. ],
[0.877, 0.493, 0. ],
[0.835, 0.369, 0. ],
[0.664, 0.255, 0.01 ],
[0.349, 0.149, 0.031]])
Monotone in lightness¶
Pale at zero and deep at one, so the ordering survives a greyscale print.
lum = spine_score_map(256) @ np.array([0.2126, 0.7152, 0.0722])
print(f"luminance at score 0: {lum[0]:.3f}, at score 1: {lum[-1]:.3f}")
luminance at score 0: 0.964, at score 1: 0.183
See also¶
spine_data_plot, spine_network_plot.