Python matplotlib.offsetbox() Examples
The following are 1 code examples for showing how to use matplotlib.offsetbox(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
matplotlib
, or try the search function
.
Example 1
Project: artificio Author: ankonzoid File: CV_plot_utils.py License: Apache License 2.0 | 5 votes |
def plot_tsne(X, imgs, outFile): def imscatter(x, y, images, ax=None, zoom=1.0): if ax is None: ax = plt.gca() x, y = np.atleast_1d(x, y) artists = [] for x0, y0, img0 in zip(x, y, images): im = OffsetImage(img0, zoom=zoom) ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=True) artists.append(ax.add_artist(ab)) ax.update_datalim(np.column_stack([x, y])) ax.autoscale() return artists def plot_embedding(X, imgs, title=None): x_min, x_max = np.min(X, 0), np.max(X, 0) X = (X - x_min) / (x_max - x_min) plt.figure() ax = plt.subplot(111) for i in range(X.shape[0]): plt.text(X[i, 0], X[i, 1], ".", fontdict={'weight': 'bold', 'size': 9}) if hasattr(offsetbox, 'AnnotationBbox'): imscatter(X[:,0], X[:,1], imgs, zoom=0.3, ax=ax) plt.xticks([]), plt.yticks([]) if title is not None: plt.title(title, fontsize=18) tsne = manifold.TSNE(n_components=2, init='pca', random_state=0) X_tsne = tsne.fit_transform(X) plot_embedding(X_tsne, imgs, "t-SNE embeddings") if outFile is None: plt.show() else: plt.savefig(outFile, bbox_inches='tight') plt.close() # Plot image reconstructions