Example #1
0
def plot_images(ax, xData, yData, ims, width_physical=None, labs=None, normalize=True):
    if labs is None:
        labs = ["" for _ in range(len(ims))]
    if normalize:
        vmin, vmax = np.min(ims), np.max(ims)
        ims_plot = (ims - vmin) / (vmax - vmin) # normalize
        ims_plot[:, 0, 0] = 1 # keep topleft pixel 1 to enforce normalization

    for idx, (x, y) in enumerate(zip(xData, yData)):
        if width_physical is None:
            small_im_dim = 0.5
        else:
            small_im_dim = width_physical[idx] / 8
        x -= small_im_dim / 2
        y -= small_im_dim / 2
        bb = Bbox.from_bounds(x, y, small_im_dim, small_im_dim)
        bb2 = TransformedBbox(bb, ax.transData)
        bbox_image = BboxImage(bb2, norm = None,
                                  origin=None, clip_on=False) #, cmap='gray_r')
        plt.title(labs[idx])
        bbox_image.set_data(ims_plot[idx])
        bbox_image.set_alpha(1.0)
        ax.add_artist(bbox_image)
        
        
    # Hide the right and top spines
    ax.spines['right'].set_visible(False)
    ax.spines['top'].set_visible(False)

    # Only show ticks on the left and bottom spines
    ax.yaxis.set_ticks_position('left')
    ax.xaxis.set_ticks_position('bottom')
    plt.xlim(-0.25, max(xData) + 0.5 / 2)
    plt.ylim(-0.25, max(yData) + 0.5 / 2)    
Example #2
0
    def create_artists(self, legend, orig_handle, xdescent, ydescent, width,
                       height, fontsize, trans):

        l = Line2D([xdescent + self.offset], [ydescent + height / 2.],
                   c=self.color,
                   ls="",
                   marker="o",
                   mfc=self.color,
                   mec=self.color)
        l.set_clip_on(False)

        bb = Bbox.from_bounds(
            xdescent + (width + self.space) / 3. + self.offset, ydescent,
            height * self.image_data.shape[1] / self.image_data.shape[0],
            height)

        tbb = TransformedBbox(bb, trans)
        image = BboxImage(tbb)
        image.set_data(self.image_data)
        image.set_alpha(1.0)
        legend.set_alpha(1.0)

        self.update_prop(image, orig_handle, legend)
        return [l, image]