Esempio n. 1
0
def imscatter(x, y, ax, imageData, zoom):
    images = []
    for i in range(len(x)):
        x0, y0 = x[i], y[i]
        # Convert to image
        img = imageData[i] * 255.
        img = np.transpose(img.astype(np.uint8), (1,2,0))
        alpha = (100 * (img[:,:,0]  <= 254)).astype(np.uint8)[:, :, np.newaxis]
        img = np.append(img, alpha, axis=2)
        print(img.shape)
        #img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        # Note: OpenCV uses BGR and plt uses RGB
        image = OffsetImage(img, zoom=zoom)
        ab = AnnotationBbox(image, (x0, y0), xycoords='data', frameon=False)
        images.append(ax.add_artist(ab))

    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()
Esempio n. 2
0
def imscatter(x, y, image, ax=None, zoom=2.):
    if ax is None:
        ax = plt.gca()
    try:
        image = plt.imread(image)
    except TypeError:
        pass
    im = OffsetImage(image, zoom=zoom, cmap=plt.get_cmap('gray'))
    im.set_zorder(10)
    x, y = np.atleast_1d(x, y)
    artists = []
    for x0, y0 in zip(x, y):
        ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
        ab.set_zorder(10)
        artists.append(ax.add_artist(ab))
    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()
    return artists
Esempio n. 3
0
def plot_embedding(embedding, images):
    import matplotlib.pyplot as plt
    from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(embedding[0], embedding[1], alpha=0.0)
    for i in xrange(embedding.shape[1]):
        img = numpy.zeros((images[i][1].shape[0], images[i][1].shape[1], 4))
        img[:, :, 0] = 255 * images[i][1]
        img[:, :, 1] = 255 * images[i][1]
        img[:, :, 2] = 255 * images[i][1]
        img[:, :, 3] = 1
        imagebox = OffsetImage(img, cmap=plt.cm.gray, zoom=0.5)
        ab = AnnotationBbox(imagebox, (embedding[0][i], embedding[1, i]),
                            pad=0.001,
                            frameon=False)
        ax.add_artist(ab)
    plt.show()
Esempio n. 4
0
def imscatter(x, y, ax, imageData, zoom, vae):
    """
    Inputs:
        x, y : TSNE points 
        imageData: Your images for testing 
    """
    images = []
    reconstructed_imgs = vae.predict(imageData)
    for i in range(len(x)):
        x0, y0 = x[i], y[i]
        # Convert to image
        for j in range(c):
            img = reconstructed_imgs[i,:,:,j]
            image = OffsetImage(img, zoom=zoom)
            ab = AnnotationBbox(image, (x0, y0), xycoords='data', frameon=False)
            images.append(ax.add_artist(ab))
    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()
def AddLogo(logo_name, ax, zoom=1.2):
    """Read logo from PNG file and add it to axes."""

    logo_data = read_png(logo_name)
    fig_dpi = ax.get_figure().dpi
    fig_size = ax.get_figure().get_size_inches()
    # NOTE: This scaling is kinda ad hoc...
    zoom_factor = .1 / 1.2 * fig_dpi * fig_size[0] / np.shape(logo_data)[0]
    zoom_factor *= zoom
    logo_box = OffsetImage(logo_data, zoom=zoom_factor)
    ann_box = AnnotationBbox(logo_box, [0., 1.],
                             xybox=(2., -3.),
                             xycoords="axes fraction",
                             boxcoords="offset points",
                             box_alignment=(0., 1.),
                             pad=0.,
                             frameon=False)
    ax.add_artist(ann_box)
def imscatter(x, y, image, ax=None, zoom=1):
    #taken from https://stackoverflow.com/questions/22566284/matplotlib-how-to-plot-images-instead-of-points
    if ax is None:
        ax = plt.gca()
    try:
        image = plt.imread(image)
    except TypeError:
        # Likely already an array...
        pass
    im = OffsetImage(image, zoom=zoom)
    x, y = np.atleast_1d(x, y)
    artists = []
    for x0, y0 in zip(x, y):
        ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
        artists.append(ax.add_artist(ab))
    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()
    return artists
def plot_pca_examples(data, example_indices):
    plt.figure(figsize=(26, 14))
    plt.gca().set_facecolor("black")
    g = np.dstack(np.meshgrid(np.linspace(0, 11, 20),
                              np.linspace(10, 0, 10))).reshape(-1, 2)
    for i, ps in zip(example_indices, g):
        img = imdata[i, :, :, :]
        img = Image.fromarray(img)
        ab = AnnotationBbox(OffsetImage(img),
                            ps,
                            xycoords="data",
                            frameon=False,
                            box_alignment=(0, 0))
        plt.gca().add_artist(ab)
    plt.xlim(0, 11.9)
    plt.ylim(0, 11.2)
    plt.xticks([])
    plt.yticks([])
Esempio n. 8
0
def plot_xy_and_save(xy, imagesData, show_notebook=True):
    images = imagesData.extract_lowRes()
    fig = plt.figure(figsize=(170, 170))
    plt.scatter(xy[:, 0], xy[:, 1], marker=None)

    ax = plt.subplot(111)

    for i in range(len(images)):
        im = OffsetImage(images[i], cmap='gray', zoom=0.70)
        im.image.axis = ax
        ab = AnnotationBbox(im, [xy[i, 0], xy[i, 1]], frameon=False)
        ax.add_artist(ab)
    if (not show_notebook):
        filename = easygui.filesavebox(msg="Give a name to your plot")
        fig.savefig(filename + ".jpg")

    else:
        plt.show()
Esempio n. 9
0
def imscatter(x, y, ax=None, zoom=1):
    i = 1
    for x0, y0 in zip(x, y):
        image = get_sample_data('/Users/mac/Desktop/%d.png' % i)
        if ax is None:
            ax = plt.gca()
        try:
            image = plt.imread(image)
        except TypeError:
            pass
        im = OffsetImage(image, zoom=zoom)
        artists = []
        ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
        artists.append(ax.add_artist(ab))
        i += 1
    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()
    return artists
Esempio n. 10
0
    def southsea(self,
                 ax=None,
                 logo_file="south_china_sea_01.jpg",
                 alpha=1.0,
                 zoom=0.4,
                 loc='left_bottom'):
        """
        Add China south sea image.

        Args:
            ax (object, optional): Axes instance, if not None then overrides the default axes instance.
            logo_file (str, optional): logo file name. Defaults to "nmc_medium.png".
            alpha (float, optional): logo transparency. Defaults to 0.7.
            zoom (int, optional): logo zoom scale. Defaults to 1.
            loc (str, optional): logo image location, 'right_bottom', 'left_bottom'.
        """

        #Get current axes if not specified
        ax = ax or self._check_ax()

        #Check logo file
        if not os.path.isfile(logo_file):
            logo_file = pkg_resources.resource_filename(
                'nmc_met_graphics', os.path.join("resources/logo/", logo_file))
        img = Image.open(logo_file)

        corner = ax.get_extent(crs=ccrs.PlateCarree())
        if loc.upper() == "LEFT_BOTTOM":
            position = [corner[0], corner[2]]
            box_alignment = (-0.005, -0.005)
        else:
            position = [corner[1], corner[2]]
            box_alignment = (1.0, 0.0)

        imagebox = OffsetImage(img, zoom=zoom, alpha=alpha, resample=True)
        imagebox.image.axes = ax
        transform = ccrs.PlateCarree()._as_mpl_transform(ax)
        ab = AnnotationBbox(imagebox,
                            position,
                            xycoords=transform,
                            box_alignment=box_alignment,
                            pad=0,
                            frameon=False)
        return ax.add_artist(ab)
Esempio n. 11
0
def imageScatter(x,y,imgs,cls=None,probs=None,labels=None,ax=None,img_scale=(50,50),frame_width=3):
    '''scatter plot showing thumbnails as scatter symbols with frame and text for visualizing different things'''
    # from scipy.misc import imresize # deprecated, better pass PIL Image instead
    if ax is None:
        ax = plt.gca()
    if cls is not None:
        uniqueCls = np.unique(cls)
        classInd = [np.where(uniqueCls==cl)[0][0] for cl in cls]
        clsCols = np.multiply(matplotlib.cm.rainbow(np.linspace(0, 1, len(uniqueCls))),255)
        clsCols = np.delete(clsCols, 3, 1)

    for ind in range(len(x)):
        if type(imgs[ind]) == PIL.JpegImagePlugin.JpegImageFile:
            img = imgs[ind].resize(img_scale,resample=PIL.Image.BICUBIC)
        else:
            #img = imresize(imgs[ind],img_scale)
            img = np.array(PIL.Image.fromarray(imgs[ind][...,:3]).resize(img_scale))

        if cls is not None:
            img = frameImage(img,clsCols[classInd[ind]],frame_width,3,True)
        if probs is not None:
            img = frameImage(img,probs[ind],frame_width,12)

        im = OffsetImage(img, zoom=1)
        xa, ya = np.atleast_1d(x[ind], y[ind])
        artists = []
        for x0, y0 in zip(xa, ya):
           ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False,box_alignment=(0.5,0.5))
           artists.append(ax.add_artist(ab))
        ax.update_datalim(np.column_stack([x, y]))
        ax.autoscale()

        font = {'family': 'serif',
                'color': 'red',
                'weight': 'normal',
                'size': 30,
                }

        if labels != None:
            ax.text(xa, ya, str(labels[ind]), fontdict=font)
            ax.set_zorder(1)


    return artists
def make_team_swarm(df, save=True, y_lim_min=-10, ylim_max=100):
    fig, axs = plt.subplots(4, 8, figsize=(20,25), sharex=True)
    team_list = sorted(df.index.drop_duplicates())
    axs_list = [item for sublist in axs for item in sublist] 
    
    for team, ax in zip(team_list, axs_list):
        sns.swarmplot(df.loc[df.index==team, df.columns[0]], 
                    ax=ax, color=nfl_color_map[team])
        
        #formatting
        ax.spines['left'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax.spines['right'].set_visible(False)
        ax.spines['bottom'].set_visible(False)
        ax.tick_params(
            which='both',
            bottom=False,
            left=False,
            right=False,
            top=False
        )
        ax.set_xlabel(None)
        ax.set_xlim(y_lim_min, ylim_max)
        #Add grid
        ax.grid(zorder=0,alpha=.4)
        ax.set_axisbelow(True)
        
        # word marks
        logo_path = nfl_wordmark_path_map[team]
        image = OffsetImage(plt.imread(logo_path), zoom=.5)
        ax.add_artist(AnnotationBbox(image, xy=(0.5,1.0), frameon=False, xycoords='axes fraction'))
    
    fig.tight_layout()

    #title
    col_name = df.columns[0].title().replace('_', ' ')
    year = df['year'].max()
    week = df['week'].max()
    fig.suptitle(f'{year} {col_name} Team By Team Distribution (Through Week {week})', fontsize=30, fontweight='bold', x=0.5, y=1.05, ha='center')
    plt.figtext(0.92, -0.03, 'Data: @NFLfastR\nViz: @MulliganRob', fontsize=12)

    if save:
        col_name_lower = col_name.lower().replace(' ', '_')
        fig.savefig(path.join(FIGURE_DIR, f'{year}_through_week_{week}_{col_name_lower}_swarmplot.png'), bbox_inches='tight')
Esempio n. 13
0
def performance_measure(sess, df_test, targets, op):
    """
    1. Visualize latent space on test set, color by label.
    2. Train K mean algorithm on latent space of training data, test clustering on test set.
    """
    all_results = os.listdir(results_path)
    figures_path = results_path + '/' + all_results[-1] + '/figures'
    if not os.path.exists(figures_path):
        os.mkdir(figures_path)

    n_batches = int(len(df_test) / batch_size)
    start = 0
    all_latent = []
    for b in range(1, n_batches + 1):
        df_feed, start = next_batch(df_test, batch_size, start)
        #print(df_feed.shape)
        x = sess.run(op, feed_dict={x_input: df_feed})
        #all_latent.append(x)
        all_latent = all_latent + x.tolist()
        #all_latent.append(x.tolist())
    ## NOW PLOT LATENT SPACE WITH COLORS
    all_latent = np.array(all_latent)
    all_latent = all_latent.reshape((2, len(all_latent)))
    '''
    ## Colored scatter plot
    '''
    plt.scatter(x=all_latent[0], y=all_latent[1], c=targets[:640])
    plt.savefig(figures_path + '/scatter.png')
    '''
    ## scatter plot with actual logos
    '''
    def getImage(path, zoom=0.07):
        return OffsetImage(plt.imread(path), zoom=zoom)

    fig, ax = plt.subplots()
    ax.scatter(all_latent[0], all_latent[1])
    artists = []
    for x0, y0, path in zip(all_latent[0], all_latent[1],
                            testing_filenames[:640]):
        ab = AnnotationBbox(getImage(str('./Data/test_set/' + path)), (x0, y0),
                            frameon=False)
        artists.append(ax.add_artist(ab))
    plt.savefig(figures_path + '/logo_scatter.png')
Esempio n. 14
0
def inset_images(ax, z, att_index, images, edgecolor='k', rho_delta = 10):
    for att_img, att_idx in zip(images, att_index):
        coord_x, = z[att_idx,0]
        coord_y, = z[att_idx,1]
        rho, phi = cart2pol(coord_x, coord_y)
        coord_x_offs, coord_y_offs = pol2cart(rho+rho_delta, phi)
        im = OffsetImage(att_img, zoom=0.2)
        ab = AnnotationBbox(
                        offsetbox=im, 
                        xy=(coord_x, coord_y),
                        xybox=(coord_x_offs, coord_y_offs),
                        boxcoords='data',
                        pad=0.1,
                        bboxprops={'edgecolor': edgecolor},
                        arrowprops=dict(arrowstyle='-', color='k'),
                        frameon=True)

        ax.add_artist(ab)
    return ax
Esempio n. 15
0
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()
Esempio n. 16
0
    def display_points(self, image_idx, image):
        visible_points_coords = self.database.get_visible_points_coords(image)
        self.clear_images(image_idx)

        for point_id, coords in visible_points_coords.items():
            color = distinct_colors[divmod(hash(point_id), 19)[1]]
            text_path = TextPath((0, 0), point_id, size=10)
            p1 = PathPatch(text_path, transform=IdentityTransform(), alpha=1, color=color)
            offsetbox2 = AuxTransformBox(IdentityTransform())
            offsetbox2.add_artist(p1)
            ab = AnnotationBbox(offsetbox2, ((coords[0] + 30), (coords[1] + 30)), bboxprops=dict(alpha=0.05))
            circle = mpatches.Circle((coords[0], coords[1]), 20, color=color, fill=False)

            self.plt_artists[image_idx].append(ab)
            self.plt_artists[image_idx].append(circle)

            self.subplots[image_idx].add_artist(ab)
            self.subplots[image_idx].add_artist(circle)
        self.figures[image_idx].canvas.draw_idle()
Esempio n. 17
0
    def init_ui(self):
        sns.set()

        self.fig = figure(num=None, figsize=(8, 6), dpi=80)
        self.canvas = FigureCanvas(self.fig)
        self.ax = self.fig.add_subplot(111)
        self.verticalLayout.addWidget(self.canvas)
        #  so this just loads the png file to a class variable lakers
        lakers = mpimg.imread(
            'Resources/TeamLogos/los-angeles-lakers-logo-symbol.png')
        # Im not sure what this does but i think it just makes it drawable
        imagebox = OffsetImage(lakers, zoom=0.1)
        # this makes an annotation on the matplotlib figure
        ab = AnnotationBbox(imagebox, (0.4, 0.6),
                            xycoords='data',
                            frameon=False)
        # and this adds it... i think..
        self.ax.add_artist(ab)
        self.canvas.draw()
Esempio n. 18
0
    def add_fruit(self, pos, value=None):
        if self.animated:
            fruit_idx = random.randint(0, len(self.fruits_paths) - 1)
            fruit_path = self.fruits_paths[fruit_idx]
            img = plt.imread(fruit_path)
            off_img = OffsetImage(img, zoom=0.3)
            bbox = AnnotationBbox(off_img, (pos[1], pos[0]), frameon=False)
            fruit = self.ax.add_artist(bbox)
        else:
            fruit = None

        # choose value of fruit and update the tracking map
        if not value:
            value = random.randint(3, self.max_fruit_score)
        self.map[pos[0], pos[1]] = value

        # update fruits_on_board tracking
        board_time = self.min_fruit_time * 2
        self.fruits_on_board[pos] = {'fruit_art':fruit, 'value': value, 'board_time_left': board_time}
Esempio n. 19
0
def error():
    """
    """
    # http://matplotlib.org/examples/pylab_examples/demo_annotation_box.html
    from matplotlib._png import read_png
    from matplotlib.cbook import get_sample_data
    from matplotlib.offsetbox import OffsetImage
    from matplotlib.offsetbox import AnnotationBbox
    import os
    fn = get_sample_data(os.path.join(
                         os.path.dirname(__file__),
                         "static",
                         "white-background.png"),
                         asfileobj=False)
    image = read_png(fn)
    imagebox = OffsetImage(image)
    xy = (0.5, 0.5)
    ab = AnnotationBbox(imagebox, xy)
    return ab
Esempio n. 20
0
def imscatter(x, y, image, ax=None, zoom=1):
    if ax is None:
        #print("a")
        ax = plt.gcf()
    try:
        #print("a")
        image = plt.imread(image)
    except TypeError:
        # Likely already an array...
        pass
    im = OffsetImage(image, zoom=zoom)
    x, y = np.atleast_1d(x, y)
    artists = []
    for x0, y0 in zip(x, y):
        ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
        artists.append(ax.add_artist(ab))
    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()
    return artists
Esempio n. 21
0
def imscatter(x, y, imageSize, ax, imageData, zoom):
    images = []
    for i in range(len(x)):
        x0, y0 = x[i], y[i]

        # Convert to image
        img = imageData[i] * 255.
        img = img.astype(np.uint8).reshape([imageSize, imageSize])
        img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)

        #img = cv2.resize(img, (imageSize, imageSize), interpolation = cv2.INTER_LINEAR)

        # Note: OpenCV uses BGR and plt uses RGB
        image = OffsetImage(img, zoom=zoom)
        ab = AnnotationBbox(image, (x0, y0), xycoords='data', frameon=False)
        images.append(ax.add_artist(ab))

    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()
Esempio n. 22
0
def draw_puzzle_inline(grid, star):
    my_dpi = 100
    plotsize = 773
    fig, ax = plt.subplots(figsize=(plotsize / my_dpi, plotsize / my_dpi),
                           dpi=my_dpi)
    mat = ax.imshow(grid, cmap='Set3', interpolation='nearest')
    plt.xticks([])
    plt.yticks([])
    plt.savefig('puzzle.png', bbox_inches='tight', pad_inches=0)
    arr_img = plt.imread('battle_star/duck1.png')
    imagebox = OffsetImage(arr_img, zoom=0.6)
    for x in range(star.shape[0]):
        for y in range(star.shape[1]):
            if star[x, y] == 1:
                ab = AnnotationBbox(imagebox, (y, x),
                                    xycoords='data',
                                    frameon=False)
                ax.add_artist(ab)
    plt.show()
    def PlotObstacles(self):
        """
        Plots the obstacles and the starting position.
        """
        # Plot the Starting position        
        plt.plot(self.start.means[-1,0,:], self.start.means[-1,1,:], "Xr",markersize=20)        
        plt.axis([-1.3, 1.3, -0.3, 2.3])
        # Plot the environment boundary
        xy, w, h = (-1.2, -0.2), 2.4, 2.2
        r = Rectangle(xy, w, h, fc='none', ec='gold', lw=1)        
        offsetbox = AuxTransformBox(plt.axes().transData)
        offsetbox.add_artist(r)
        ab = AnnotationBbox(offsetbox, (xy[0]+w/2.,xy[1]+w/2.),
                            boxcoords="data", pad=0.52,fontsize=20,
                            bboxprops=dict(facecolor = "none", edgecolor='k', 
                                      lw = 20))
        plt.axes().add_artist(ab) 
        
        # Change ticklabel font size
        plt.xticks(fontsize=30)
        plt.yticks(fontsize=30)
        # Plot the rectangle obstacles
        obstacles = [Rectangle(xy        = [ox, oy], 
                               width     = wd, 
                               height    = ht, 
                               angle     = 0, 
                               color     = "k", 
                               facecolor = "k",) for (ox, oy, wd, ht) in self.obstacleList]
        for obstacle in obstacles:
            plt.axes().add_artist(obstacle)     
            
        # Data for plotting the shaded goal region
        goalHeight = self.ymingoal
        x          = [-1.20,-1.15,-1.10,-1.05, -1.00]         
        y1         = [goalHeight]*len(x)
        
        plt.text(-1.10, 1.0, 'GOAL', rotation=0, weight="bold", color='white', size=20,horizontalalignment='center', verticalalignment='top', multialignment='center')

        
        # Shade the area between y1 and line y=2.10
        plt.fill_between(x, y1, self.ymaxgoal,
                         facecolor="#CAB8CB", # The fill color
                         color='#CAB8CB')     # The outline color 
def plot_obj_pc_multi(object_type, labels, img, alpha=0.25):
    #labels=['Vehicle', 'Pedestrian', 'Cyclist']
    #'waymo_top.png'
    fig, ax = plt.subplots(1, 3, figsize=(10, 3))

    color = ['blue', 'orange', 'green', 'red', 'yellow']

    for i, each in enumerate(object_type):
        xdata = each['location_x']
        ydata = each['location_y']
        ax[i].scatter(xdata, ydata, alpha=alpha, s=0.25, color=color[i])
        ax[i].set_title(labels[i])
        x = 0
        y = 0
        ax[i].scatter(x, y)

        ab = AnnotationBbox(getImage(img), (x, y), frameon=False)
        ax[i].add_artist(ab)
        ax[i].axis('off')
Esempio n. 25
0
    def imscatter3(self, pos, Cnlist, ax=None, zoom=1):
        import matplotlib.pyplot as plt
        from matplotlib.offsetbox import OffsetImage, AnnotationBbox
        import numpy as np

        if ax is None:
            ax = plt.gca()
        artists = []
        for Cn in Cnlist:
            filepath = self.genus + "/" + Cn + ".png"
            image = plt.imread(filepath)
            im = OffsetImage(image, zoom=zoom)
            x, y = np.atleast_1d(pos[Cn][0], pos[Cn][1])
            for x0, y0 in zip(x, y):
                ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
                artists.append(ax.add_artist(ab))
            ax.update_datalim(np.column_stack([x, y]))
            ax.autoscale()
        return artists
Esempio n. 26
0
    def receive_map(self) -> None:
        """
        Updates the UI when a new map is available for display
        """
        children = self.plotWidget.canvas.ax.get_children()
        for c in children:
            if isinstance(c, AnnotationBbox):
                c.remove()

        zoom, radius, map_image, mark = self.map_data.get_map_value()

        # plotMap UI modification
        self.plotWidget.canvas.ax.set_axis_off()
        self.plotWidget.canvas.ax.set_ylim(map_image.shape[0], 0)
        self.plotWidget.canvas.ax.set_xlim(0, map_image.shape[1])

        # Removes pesky white boarder
        self.plotWidget.canvas.fig.subplots_adjust(left=0,
                                                   bottom=0,
                                                   right=1,
                                                   top=1,
                                                   wspace=0,
                                                   hspace=0)

        if self.im:
            # Required because plotting images over old ones creates memory leak
            # NOTE: im.set_data() can also be used
            self.im.remove()

        self.im = self.plotWidget.canvas.ax.imshow(map_image)

        # updateMark UI modification
        annotation_box = AnnotationBbox(OffsetImage(MAP_MARKER),
                                        mark,
                                        frameon=False)
        self.plotWidget.canvas.ax.add_artist(annotation_box)

        # For debugging marker position
        #self.plotWidget.canvas.ax.plot(mark[0], mark[1], marker='o', markersize=3, color="red")

        self.plotWidget.canvas.draw()

        MAP_UPDATED_EVENT.increment()
Esempio n. 27
0
def visualize_scatter_with_images(X_2d_data,
                                  images,
                                  layer,
                                  saveFig=True,
                                  figsize=(45, 45),
                                  image_zoom=1):
    fig, ax = plt.subplots(figsize=figsize)
    artists = []
    for xy, i in zip(X_2d_data, images):
        x0, y0 = xy
        img = OffsetImage(np.array(i), zoom=image_zoom)
        ab = AnnotationBbox(img, (x0, y0), xycoords='data', frameon=False)
        artists.append(ax.add_artist(ab))
    ax.update_datalim(X_2d_data)
    ax.autoscale()
    fig.suptitle('tSNE of ' + layer + ' activations', fontsize=60)
    # plt.title('tSNE of feature layers')
    plt.show()
    return fig
Esempio n. 28
0
def visualize_zs(zs, shapes, captions, keys, class_ids, ixtoword):
    fig, ax = plt.subplots(figsize=(50, 50))
    colors = [
        "red", "green", "blue", "orange", "purple", "brown", "fuchsia", "grey",
        "olive", "lightblue"
    ]
    points = TSNE(n_components=2, random_state=0).fit_transform(zs)

    for i, (p, s, k, key,
            l) in enumerate(zip(points, shapes, captions, keys, class_ids)):
        sent = []
        for n in range(len(k)):
            s_id = k.numpy()[n]
            txt = ixtoword[int(s_id)]
            if (s_id != 0):
                sent.append(txt)

        l = 1

        img = plt.imread("./tools/shape_captcha/images/" + str(key) + ".png",
                         format='png')
        imb0 = OffsetImage(img, zoom=0.1)
        imb0.image.axes = ax
        plt.tick_params(labelsize=40)
        plt.grid(which='major', color='black', linestyle='-')
        ab0 = AnnotationBbox(imb0,
                             p,
                             xybox=(40, -40),
                             xycoords="data",
                             boxcoords="offset points",
                             pad=0.2,
                             bboxprops=dict(edgecolor=colors[l]),
                             arrowprops=dict(arrowstyle="->"))
        ax.add_artist(ab0)

        print(sent)
        plt.scatter(p[0],
                    p[1],
                    marker="${}$".format(' '.join(sent)),
                    c=colors[l])
        ax.annotate(' '.join(sent), (p[0], p[1]))

    plt.savefig('./plts/search.png')
Esempio n. 29
0
 def imscatter(points, images, ax=None, zoom=1, cmap="hot"):
     if ax is None:
         ax = plt.gca()
     artists = []
     i = 0
     if not isinstance(cmap, list):
         cmap = [cmap] * len(points)
     for x0, y0 in points:
         transformed = (images[i] - np.min(images[i])) / \
             (np.max(images[i]) - np.min(images[i]))
         im = OffsetImage(transformed[:, :, 0], zoom=zoom, cmap=cmap[i])
         ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
         artists.append(ax.add_artist(ab))
         i += 1
     ax.update_datalim(np.column_stack(np.transpose(points)))
     ax.autoscale()
     ax.get_xaxis().set_ticks([])
     ax.get_yaxis().set_ticks([])
     return artists
Esempio n. 30
0
def plot_random_sample_of_images(ax,
                                 stack_file,
                                 label,
                                 xy,
                                 align,
                                 radius,
                                 n,
                                 zoom,
                                 keep=None,
                                 **extra):
    '''
    '''

    index = numpy.arange(len(xy), dtype=numpy.int)
    numpy.random.shuffle(index)
    off = numpy.argwhere(index == keep)
    if off.shape[0] > 0:
        off = off.squeeze()
        index[off] = index[0]
        index[0] = keep
    assert (n > 0)

    vals = nonoverlapping_subset(ax, xy[index], radius, n)
    index = index[vals]
    label = label[index]
    sidx = numpy.argsort(label[:, 0])
    label = label[sidx]
    if align is not None:
        align = align[index]
        align = align[sidx]

    for i, img in enumerate(iter_images(stack_file, label, align, **extra)):
        im = OffsetImage(img, zoom=zoom,
                         cmap=cm.Greys_r) if img.ndim == 2 else OffsetImage(
                             img, zoom=zoom)
        ab = AnnotationBbox(im,
                            xy[index[sidx[i]]],
                            xycoords='data',
                            xybox=(radius, 0.),
                            boxcoords="offset points",
                            frameon=False)
        ax.add_artist(ab)
    return index