当前位置: 首页>>代码示例>>Python>>正文


Python offsetbox.OffsetImage方法代码示例

本文整理汇总了Python中matplotlib.offsetbox.OffsetImage方法的典型用法代码示例。如果您正苦于以下问题:Python offsetbox.OffsetImage方法的具体用法?Python offsetbox.OffsetImage怎么用?Python offsetbox.OffsetImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.offsetbox的用法示例。


在下文中一共展示了offsetbox.OffsetImage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: show

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def show(mnist, targets, ret):
    target_ids = range(len(set(targets)))
    
    colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k', 'violet', 'orange', 'purple']
    
    plt.figure(figsize=(12, 10))
    
    ax = plt.subplot(aspect='equal')
    for label in set(targets):
        idx = np.where(np.array(targets) == label)[0]
        plt.scatter(ret[idx, 0], ret[idx, 1], c=colors[label], label=label)
    
    for i in range(0, len(targets), 250):
        img = (mnist[i][0] * 0.3081 + 0.1307).numpy()[0]
        img = OffsetImage(img, cmap=plt.cm.gray_r, zoom=0.5) 
        ax.add_artist(AnnotationBbox(img, ret[i]))
    
    plt.legend()
    plt.show() 
开发者ID:peisuke,项目名称:MomentumContrast.pytorch,代码行数:21,代码来源:test.py

示例2: ab_plotter

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def ab_plotter(xcoords, ycoords, images, labels):

    ax = plt.subplot(111)
    ax.set_xlim([-30, 30])
    ax.set_ylim([-30, 30])
    
    for x, y, i, l in zip(xcoords, ycoords, images, labels):
        arr_hand = i
        imagebox = OffsetImage(arr_hand, zoom=.1)
        xy = [x, y]               # coordinates to position this image
        
        ab = AnnotationBbox(imagebox, xy,
            xybox=(10., -10.),
            xycoords='data',
            boxcoords="offset points",
            pad=0.0)                                  
        ax.annotate(ab, xy = xy)
    
    # rest is just standard matplotlib boilerplate
    ax.grid(True)
    plt.show() 
开发者ID:elliottd,项目名称:GroundedTranslation,代码行数:23,代码来源:plot_tsne.py

示例3: getImage

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def getImage(path, new_size = 20):
    # return OffsetImage(plt.imread(path))
    img = Image.open(path)
    img = crop_max_square(img)
    img.thumbnail((new_size, new_size), Image.BILINEAR)  # resizes image in-place

    return OffsetImage(img) 
开发者ID:jing-vision,项目名称:lightnet,代码行数:9,代码来源:tsne.py

示例4: plot_embedding

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def plot_embedding(X, y, imgs=None, title=None, name=None):
    # Adapted from http://scikit-learn.org/stable/auto_examples/manifold/plot_lle_digits.html
    x_min, x_max = np.min(X, 0), np.max(X, 0)
    X = (X - x_min) / (x_max - x_min)

    # Plot colors numbers
    plt.figure(figsize=(10,10))
    ax = plt.subplot(111)
    for i in range(X.shape[0]):
        # plot colored number
        plt.text(X[i, 0], X[i, 1], str(y[i]),
                 color=plt.cm.Set1(y[i] / 10.),
                 fontdict={'weight': 'bold', 'size': 9})

    # Add image overlays
    if imgs is not None and hasattr(offsetbox, 'AnnotationBbox'):
        # only print thumbnails with matplotlib > 1.0
        shown_images = np.array([[1., 1.]])  # just something big
        for i in range(X.shape[0]):
            dist = np.sum((X[i] - shown_images) ** 2, 1)
            if np.min(dist) < 4e-3:
                # don't show points that are too close
                continue
            shown_images = np.r_[shown_images, [X[i]]]
            imagebox = offsetbox.AnnotationBbox(
                offsetbox.OffsetImage(imgs[i], cmap=plt.cm.gray_r), X[i])
            ax.add_artist(imagebox)

    plt.xticks([]), plt.yticks([])
    if title is not None:
        plt.title(title)

    plt.savefig("results/" + str(name) + '.svg') 
开发者ID:vithursant,项目名称:MagnetLoss-PyTorch,代码行数:35,代码来源:utils.py

示例5: getImage

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def getImage(self,path, zoom=10):
        return OffsetImage(plt.imread(path), zoom=zoom)

    #TODO update proportions according to the image size 
开发者ID:acsicuib,项目名称:YAFS,代码行数:6,代码来源:animation.py

示例6: plot_tsne

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [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 
开发者ID:ankonzoid,项目名称:artificio,代码行数:42,代码来源:CV_plot_utils.py

示例7: plot_embedding

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def plot_embedding(X, 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], str(y[i]),
                 color=plt.cm.Set1(y[i] / 10.),
                 fontdict={'weight': 'bold', 'size': 9})

    if hasattr(offsetbox, 'AnnotationBbox'):
        # only print thumbnails with matplotlib > 1.0
        shown_images = np.array([[1., 1.]])  # just something big
        for i in range(X.shape[0]):
            dist = np.sum((X[i] - shown_images) ** 2, 1)
            if np.min(dist) < 4e-3:
                # don't show points that are too close
                continue
            shown_images = np.r_[shown_images, [X[i]]]
            imagebox = offsetbox.AnnotationBbox(
                offsetbox.OffsetImage(digits.images[i], cmap=plt.cm.gray_r),
                X[i])
            ax.add_artist(imagebox)
    plt.xticks([]), plt.yticks([])
    if title is not None:
        plt.title(title)


# ----------------------------------------------------------------------
# Plot images of the digits 
开发者ID:VarIr,项目名称:scikit-hubness,代码行数:33,代码来源:plot_lle_digits.py

示例8: plot_embedding

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def plot_embedding(X, 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], str(digits.target[i]),
                 color=plt.cm.Set1(y[i] / 10.),
                 fontdict={'weight': 'bold', 'size': 9})
   
    '''
    if hasattr(offsetbox, 'AnnotationBbox'):
        # only print thumbnails with matplotlib > 1.0
        shown_images = np.array([[1., 1.]])  # just something big
        for i in range(digits.data.shape[0]):
            dist = np.sum((X[i] - shown_images) ** 2, 1)
            if np.min(dist) < 4e-3:
                # don't show points that are too close
                continue
            shown_images = np.r_[shown_images, [X[i]]]
            imagebox = offsetbox.AnnotationBbox(
                offsetbox.OffsetImage(digits.images[i], cmap=plt.cm.gray_r),
                X[i])
            ax.add_artist(imagebox)
    '''
    plt.xticks([]), plt.yticks([])
    if title is not None:
        plt.title(title)


#----------------------------------------------------------------------
# Plot images of the digits 
开发者ID:PacktPublishing,项目名称:Computer-Vision-with-Python-3,代码行数:36,代码来源:tsne.py

示例9: plot_embedding

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def plot_embedding(Xp, y, imgs, title=None, figsize=(12, 4)):
    x_min, x_max = numpy.min(Xp, 0), numpy.max(Xp, 0)
    X = (Xp - x_min) / (x_max - x_min)

    fig, ax = plt.subplots(1, 2, figsize=figsize)
    for i in range(X.shape[0]):
        ax[0].text(X[i, 0], X[i, 1], str(y[i]),
                   color=plt.cm.Set1(y[i] / 10.),
                   fontdict={'weight': 'bold', 'size': 9})

    if hasattr(offsetbox, 'AnnotationBbox'):
        # only print thumbnails with matplotlib > 1.0
        shown_images = numpy.array([[1., 1.]])  # just something big
        for i in range(X.shape[0]):
            dist = numpy.sum((X[i] - shown_images) ** 2, 1)
            if numpy.min(dist) < 4e-3:
                # don't show points that are too close
                continue
            shown_images = numpy.r_[shown_images, [X[i]]]
            imagebox = offsetbox.AnnotationBbox(
                offsetbox.OffsetImage(imgs[i], cmap=plt.cm.gray_r),
                X[i])
            ax[0].add_artist(imagebox)
    ax[0].set_xticks([]), ax[0].set_yticks([])
    ax[1].plot(Xp[:, 0], Xp[:, 1], '.')
    if title is not None:
        ax[0].set_title(title)
    return ax 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:30,代码来源:plot_custom_model.py

示例10: plot_embedding

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def plot_embedding(X, 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], str(digits.target[i]),
                 color=plt.cm.Set1(y[i] / 10.),
                 fontdict={'weight': 'bold', 'size': 9})

    if hasattr(offsetbox, 'AnnotationBbox'):
        # only print thumbnails with matplotlib > 1.0
        shown_images = np.array([[1., 1.]])  # just something big
        for i in range(digits.data.shape[0]):
            dist = np.sum((X[i] - shown_images) ** 2, 1)
            if np.min(dist) < 4e-3:
                # don't show points that are too close
                continue
            shown_images = np.r_[shown_images, [X[i]]]
            imagebox = offsetbox.AnnotationBbox(
                offsetbox.OffsetImage(digits.images[i], cmap=plt.cm.gray_r),
                X[i])
            ax.add_artist(imagebox)
    plt.xticks([]), plt.yticks([])
    if title is not None:
        plt.title(title) 
开发者ID:kastnerkyle,项目名称:PyCon2015,代码行数:29,代码来源:ex3_digits.py

示例11: plot_embedding

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
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') 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:50,代码来源:__init__.py

示例12: _tsne_plot_embedding

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def _tsne_plot_embedding(self, x, y, inputs, path_result_image, title=""):
        x_min, x_max = np.min(x, 0), np.max(x, 0)
        x_normalized = (x - x_min) / (x_max - x_min)

        tableau20 = style.generate_tableau20_colors()
        figure = plt.figure()
        figure.set_size_inches(18.5, 10.5)
        ax = figure.add_subplot(111)
        ax.axis('off')
        for i in xrange(x.shape[0]):
            plt.text(x_normalized[i, 0], x_normalized[i, 1], str(y[i]),
                     color=tableau20[y[i]],
                     fontdict={'weight': 'bold', 'size': 12})

        labels = [mpatches.Patch(color=tableau20[output_descriptor.value],
                                 label="[{0}] {1}".format(output_descriptor.value, output_descriptor.name)) for output_descriptor in list(self.output_descriptor_enum)]
        legend = ax.legend(handles=labels, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., frameon=False)

        if hasattr(offsetbox, 'AnnotationBbox'): # only print thumbnails with matplotlib > 1.0
            shown_images = np.array([[1., 1.]])
            for i in xrange(len(x_normalized)):
                distance_between_points = np.sum((x_normalized[i] - shown_images) ** 2, 1)
                if np.min(distance_between_points) < self.MIN_DISTANCE_BETWEEN_IMAGES:
                    continue
                shown_images = np.r_[shown_images, [x_normalized[i]]]
                rendered_image = offsetbox.OffsetImage(self._state_into_grid_of_screenshots(inputs[i]),
                                                       cmap=plt.get_cmap('gray'))
                image_position = x_normalized[i]
                annotation_box_relative_position = (-70, 250) if x_normalized[i][1] > 0.5 else (-70, -250)
                imagebox = offsetbox.AnnotationBbox(rendered_image, image_position,
                                                    xybox=annotation_box_relative_position,
                                                    xycoords='data',
                                                    boxcoords="offset points",
                                                    arrowprops=dict(arrowstyle="->"))
                ax.add_artist(imagebox)

        plt.xticks([]), plt.yticks([])
        if title is not None:
            plt.title(title)

        plt.savefig(path_result_image, bbox_extra_artists=(legend,), bbox_inches='tight', pad_inches=4)
        print("Visualization written to {0}".format(path_result_image)) 
开发者ID:lopespm,项目名称:agent-trainer,代码行数:44,代码来源:tsne.py

示例13: digits_plot

# 需要导入模块: from matplotlib import offsetbox [as 别名]
# 或者: from matplotlib.offsetbox import OffsetImage [as 别名]
def digits_plot():
    digits = datasets.load_digits(n_class=6)
    n_digits = 500
    X = digits.data[:n_digits]
    y = digits.target[:n_digits]
    n_samples, n_features = X.shape
    n_neighbors = 30

    def plot_embedding(X, 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], str(digits.target[i]),
                    color=plt.cm.Set1(y[i] / 10.),
                    fontdict={'weight': 'bold', 'size': 9})

        if hasattr(offsetbox, 'AnnotationBbox'):
            # only print thumbnails with matplotlib > 1.0
            shown_images = np.array([[1., 1.]])  # just something big
            for i in range(X.shape[0]):
                dist = np.sum((X[i] - shown_images) ** 2, 1)
                if np.min(dist) < 1e5:
                    # don't show points that are too close
                    # set a high threshold to basically turn this off
                    continue
                shown_images = np.r_[shown_images, [X[i]]]
                imagebox = offsetbox.AnnotationBbox(
                    offsetbox.OffsetImage(digits.images[i], cmap=plt.cm.gray_r),
                    X[i])
                ax.add_artist(imagebox)
        plt.xticks([]), plt.yticks([])
        if title is not None:
            plt.title(title)

    n_img_per_row = 10
    img = np.zeros((10 * n_img_per_row, 10 * n_img_per_row))
    for i in range(n_img_per_row):
        ix = 10 * i + 1
        for j in range(n_img_per_row):
            iy = 10 * j + 1
            img[ix:ix + 8, iy:iy + 8] = X[i * n_img_per_row + j].reshape((8, 8))

    plt.imshow(img, cmap=plt.cm.binary)
    plt.xticks([])
    plt.yticks([])
    plt.title('A selection from the 64-dimensional digits dataset')
    print("Computing PCA projection")
    pca = decomposition.PCA(n_components=2).fit(X)
    X_pca = pca.transform(X)
    plot_embedding(X_pca, "Principal Components projection of the digits")
    plt.figure()
    plt.matshow(pca.components_[0, :].reshape(8, 8), cmap="gray")
    plt.axis('off')
    plt.figure()
    plt.matshow(pca.components_[1, :].reshape(8, 8), cmap="gray")
    plt.axis('off')
    plt.show() 
开发者ID:amueller,项目名称:scipy_2015_sklearn_tutorial,代码行数:62,代码来源:plot_digits_datasets.py


注:本文中的matplotlib.offsetbox.OffsetImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。