本文整理匯總了Python中matplotlib.offsetbox方法的典型用法代碼示例。如果您正苦於以下問題:Python matplotlib.offsetbox方法的具體用法?Python matplotlib.offsetbox怎麽用?Python matplotlib.offsetbox使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib
的用法示例。
在下文中一共展示了matplotlib.offsetbox方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: plot_tsne
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import offsetbox [as 別名]
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