Note
Go to the end to download the full example code.
Using the cluster function to label clusters¶
run this example as a notebook — or grab the .ipynb (also linked at the bottom of the page)
Here is an example where we generate some synthetic data, and then use the cluster function to get cluster labels, which we can then pass to the hue kwarg to color our points by cluster.

/home/docs/checkouts/readthedocs.org/user_builds/hypertools/checkouts/latest/hypertools/plot/backend.py:1353: UserWarning: Failed to switch to any interactive backend (TkAgg, QtAgg, Qt5Agg, Qt4Agg, GTK4Agg, GTK3Agg, WXAgg). Falling back to 'Agg'.
warnings.warn(BACKEND_WARNING)
# Code source: Andrew Heusser
# License: MIT
# import
import hypertools as hyp
import numpy as np
# simulate clusters (seeded so the figure is reproducible)
np.random.seed(123)
cluster1 = np.random.multivariate_normal(np.zeros(3), np.eye(3), size=100)
cluster2 = np.random.multivariate_normal(np.zeros(3)+3, np.eye(3), size=100)
data = np.vstack([cluster1, cluster2])
# get cluster labels
cluster_labels = hyp.cluster(data, n_clusters=2)
# plot
hyp.plot(data, '.', hue=cluster_labels)
Total running time of the script: (0 minutes 0.046 seconds)