def plot_embedding(data_matrix, y, labels=None, image_file_name=None, title=None, cmap='rainbow', density=False): """plot_embedding.""" import matplotlib.pyplot as plt from matplotlib import offsetbox from PIL import Image from eden.embedding import embed_dat_matrix_two_dimensions if title is not None: plt.title(title) if density: embed_dat_matrix_two_dimensions(data_matrix, y=y, instance_colormap=cmap) else: plt.scatter(data_matrix[:, 0], data_matrix[:, 1], c=y, cmap=cmap, alpha=.7, s=30, edgecolors='black') plt.xticks([]) plt.yticks([]) plt.axis('off') if image_file_name is not None: num_instances = data_matrix.shape[0] ax = plt.subplot(111) for i in range(num_instances): img = Image.open(image_file_name + str(i) + '.png') imagebox = offsetbox.AnnotationBbox(offsetbox.OffsetImage(img, zoom=1), data_matrix[i], pad=0, frameon=False) ax.add_artist(imagebox) if labels is not None: for id in range(data_matrix.shape[0]): label = str(labels[id]) x = data_matrix[id, 0] y = data_matrix[id, 1] plt.annotate(label, xy=(x, y), xytext=(0, 0), textcoords='offset points')
def plot_embedding(data_matrix, y, labels=None, image_file_name=None, title=None, cmap='rainbow', density=False): """plot_embedding.""" import matplotlib.pyplot as plt from matplotlib import offsetbox from PIL import Image from eden.embedding import embed_dat_matrix_two_dimensions if title is not None: plt.title(title) if density: embed_dat_matrix_two_dimensions(data_matrix, y=y, instance_colormap=cmap) else: plt.scatter(data_matrix[:, 0], data_matrix[:, 1], c=y, cmap=cmap, alpha=.7, s=30, edgecolors='black') plt.xticks([]) plt.yticks([]) plt.axis('off') if image_file_name is not None: num_instances = data_matrix.shape[0] ax = plt.subplot(111) for i in range(num_instances): img = Image.open(image_file_name + str(i) + '.png') imagebox = \ offsetbox.AnnotationBbox(offsetbox.OffsetImage(img, zoom=1), data_matrix[i], pad=0, frameon=False) ax.add_artist(imagebox) if labels is not None: for id in range(data_matrix.shape[0]): label = str(labels[id]) x = data_matrix[id, 0] y = data_matrix[id, 1] plt.annotate(label, xy=(x, y), xytext=(0, 0), textcoords='offset points')