GnuplotEx.ML.Embeddings (gnuplot_ex v0.5.0)

Embedding visualization for dimensionality reduction techniques.

Provides functions to visualize high-dimensional embeddings (t-SNE, UMAP, PCA, etc.) in 2D or 3D space, with points colored by class labels or clusters.

Examples

# 2D embeddings with labels
embeddings = [[1.2, 3.4], [2.1, 4.3], [1.5, 3.8], [5.2, 6.1], [5.5, 6.3]]
labels = [0, 0, 0, 1, 1]

plot = GnuplotEx.ML.Embeddings.plot(embeddings, labels,
  label_names: ["Class A", "Class B"]
)

# 3D embeddings
embeddings_3d = [[1, 2, 3], [2, 3, 4], [5, 6, 7], [6, 7, 8]]
labels = [0, 0, 1, 1]

plot = GnuplotEx.ML.Embeddings.plot(embeddings_3d, labels)

Summary

Functions

Plot 2D or 3D embeddings colored by labels.

Plot 2D embeddings colored by labels.

Plot 3D embeddings colored by labels.

Plot embeddings without labels (all same color).

Functions

plot(embeddings, labels, opts \\ [])

Plot 2D or 3D embeddings colored by labels.

Automatically detects dimensionality based on the first embedding point and creates either a 2D scatter plot or 3D scatter plot accordingly.

Parameters

  • embeddings - List of embedding vectors, each being a 2D or 3D point
  • labels - List of integer labels corresponding to each embedding

Options

  • :label_names - List of class names (default: auto-generated "Class 0", "Class 1", ...)
  • :title - Plot title (default: "Embeddings" for 2D, "3D Embeddings" for 3D)
  • :colors - Map of label indices to colors (auto-assigned if not provided)
  • :point_type - Point type (default: 7 - filled circle)
  • :point_size - Point size (default: 1.5)
  • :legend - Legend position (default: :top_right)
  • :x_label - X-axis label (default: "Dimension 1")
  • :y_label - Y-axis label (default: "Dimension 2")
  • :z_label - Z-axis label for 3D (default: "Dimension 3")

Examples

iex> embeddings = [[1.2, 3.4], [2.1, 4.3], [1.5, 3.8], [5.2, 6.1]]
iex> labels = [0, 0, 1, 1]
iex> plot = GnuplotEx.ML.Embeddings.plot(embeddings, labels)

# With custom labels and colors
iex> plot = GnuplotEx.ML.Embeddings.plot(embeddings, labels,
...>   label_names: ["Setosa", "Versicolor"],
...>   colors: %{0 => "#E95420", 1 => "#0066CC"},
...>   title: "t-SNE Visualization"
...> )

# 3D embeddings
iex> embeddings_3d = [[1, 2, 3], [2, 3, 4], [5, 6, 7]]
iex> labels = [0, 0, 1]
iex> plot = GnuplotEx.ML.Embeddings.plot(embeddings_3d, labels)

plot_2d(embeddings, labels, opts \\ [])

Plot 2D embeddings colored by labels.

Creates a 2D scatter plot with different colors/markers for each class.

Parameters

  • embeddings - List of 2D embedding vectors [x, y]
  • labels - List of integer labels corresponding to each embedding

Options

Same as plot/3, plus:

  • :x_label - X-axis label (default: "Dimension 1")
  • :y_label - Y-axis label (default: "Dimension 2")

Examples

iex> embeddings = [[1.2, 3.4], [2.1, 4.3], [5.2, 6.1]]
iex> labels = [0, 0, 1]
iex> plot = GnuplotEx.ML.Embeddings.plot_2d(embeddings, labels,
...>   title: "PCA Visualization",
...>   x_label: "PC1",
...>   y_label: "PC2"
...> )

plot_3d(embeddings, labels, opts \\ [])

Plot 3D embeddings colored by labels.

Creates a 3D scatter plot with different colors/markers for each class.

Parameters

  • embeddings - List of 3D embedding vectors [x, y, z]
  • labels - List of integer labels corresponding to each embedding

Options

Same as plot/3, plus:

  • :z_label - Z-axis label (default: "Dimension 3")

Examples

iex> embeddings = [[1, 2, 3], [2, 3, 4], [5, 6, 7]]
iex> labels = [0, 0, 1]
iex> plot = GnuplotEx.ML.Embeddings.plot_3d(embeddings, labels,
...>   title: "3D t-SNE",
...>   label_names: ["Cluster 1", "Cluster 2"]
...> )

plot_unlabeled(embeddings, opts \\ [])

Plot embeddings without labels (all same color).

Useful for unsupervised visualization or when labels are not available.

Examples

iex> embeddings = [[1, 2], [3, 4], [5, 6]]
iex> plot = GnuplotEx.ML.Embeddings.plot_unlabeled(embeddings,
...>   title: "UMAP Projection",
...>   color: "#E95420"
...> )