spine_data_plot¶

Draw your data in the space it lives in, coloured by score.

Objects are drawn in increasing order of score, so the atypical ones are never buried under the bulk. Colour limits are fixed at 0 to 1, so two figures can be compared by eye.

Syntax and options¶

from entropy_spine import spine_data_plot
help(spine_data_plot)
Help on function spine_data_plot in module entropy_spine.interface.plots:

spine_data_plot(
    result,
    *,
    title: 'str' = '',
    colour_by: 'str' = 'score',
    projection: 'str' = 'pca',
    view=(40, 22),
    marker_scale: 'float' = 1.0
)
    Draw the data in the space it lives in, coloured by score.

    One feature is drawn as value against object, two as a scatter, three as
    a 3-D scatter, and more are projected onto their first two principal
    components with the axes labelled to say so. Returns the figure.

Two features¶

%matplotlib inline
import numpy as np
from entropy_spine import spine, spine_data_plot

rng = np.random.default_rng(4242)
D = np.vstack([rng.standard_normal((200, 2)),
               [12, 12] + 0.25 * rng.standard_normal((20, 2))])
_, r2 = spine(D, "dist2median", "upper")
spine_data_plot(r2, title="two features");
No description has been provided for this image

One feature¶

Value against object, in the order you supplied.

rng = np.random.default_rng(11)
v = np.concatenate([np.abs(rng.standard_normal(120)),
                    np.abs(rng.standard_normal(8)) + 9])
_, r1 = spine(v, "asis", "upper")
spine_data_plot(r1, title="one feature");
No description has been provided for this image

Three features¶

A real 3-D axes: rotate it with the view option.

rng = np.random.default_rng(90210)
U = rng.standard_normal((20, 3))
U = U / np.linalg.norm(U, axis=1, keepdims=True)
X3 = np.vstack([0.9 * rng.standard_normal((150, 3)),
                U * (25 + 2 * rng.standard_normal((20, 1)))])
_, r3 = spine(X3, "dist2median", "upper")
spine_data_plot(r3, title="three features");
No description has been provided for this image

More than three¶

The first two principal components, with the axes labelled to say so and the variance explained. Nothing about the partition changes; only the drawing is a projection.

rng = np.random.default_rng(64)
X12 = np.vstack([rng.standard_normal((240, 12)),
                 rng.standard_normal((18, 12)) + 5])
_, r12 = spine(X12, "robustrownorm", "upper")
spine_data_plot(r12, title="twelve features");
No description has been provided for this image

When the scores bunch together¶

Three strata scoring 0, 0.18 and 1 come out as two nearly identical shades and one dark one. colour_by="stratum" spaces them evenly instead and labels the bar stratum, so nothing is misread as a score.

spine_data_plot(r3, title="coloured by stratum", colour_by="stratum");
No description has been provided for this image

See also¶

spine_plot for where the cuts came from, spine_network_plot for graphs, and spine_score_map if you are drawing your own.