Skip to content

Instantly share code, notes, and snippets.

@yjzhang
Created February 16, 2014 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yjzhang/154b8d862bdf4a367e0f to your computer and use it in GitHub Desktop.
Save yjzhang/154b8d862bdf4a367e0f to your computer and use it in GitHub Desktop.
Plotting clusterings with matplotlib and numpy
# Plotting clusterings with matplotlib
import numpy as np
import matplotlib.pyplot as plt
def plot_clusterings(data, clusterings, k):
"""
Args:
data - n x d numpy array
clusterings - 1 x n numpy array, values from 0 to k-1
k - number of clusters
"""
colormap = plt.cm.rainbow
for c in range(k):
color = colormap(float(c)/float(k))
plt.scatter(data[clusterings==c, 0], data[clusterings==c, 1], c = color)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment