def show_projections()

in tools/vis_utils.py [0:0]


def show_projections(p,
                     visdom_env=None,
                     visdom_win=None,
                     v=None,
                     image_path=None,
                     image=None,
                     title='projs',
                     cmap__='gist_ncar',
                     markersize=None,
                     sticks=None,
                     stickwidth=2,
                     stick_color=None,
                     plot_point_order=False,
                     bbox=None,
                     ):

    if image is None:
        try:
            im = Image.open(image_path).convert('RGB')
            im = np.array(im).transpose(2, 0, 1)
        except:
            im = None
            print('!cant load image %s' % image_path)
    else:
        im = image

    nkp = int(p.shape[2])

    pid = np.linspace(0., 1., nkp)

    if v is not None:
        okp = v > 0
    else:
        okp = np.ones(nkp) == 1

    possible_markers = ['o', 'x', 'd']
    markers = [possible_markers[i % len(possible_markers)]
               for i in range(len(p))]

    if markersize is None:
        msz = 50
        if nkp > 40:
            msz = 5
        markersizes = [msz]*nkp
    else:
        markersizes = [markersize]*nkp

    fig = plt.figure(figsize=[11, 11])

    if im is not None:
        plt.imshow(im.transpose((1, 2, 0)))
        plt.axis('off')

    if sticks is not None:
        if stick_color is not None:
            linecol = stick_color
        else:
            linecol = [0., 0., 0.]

        for p_ in p:
            for stick in sticks:
                if v is not None:
                    if v[stick[0]] > 0 and v[stick[1]] > 0:
                        linestyle = '-'
                    else:
                        continue
                else:
                    linestyle = '-'

                plt.plot(p_[0, stick], p_[1, stick], linestyle,
                         color=linecol, linewidth=stickwidth, zorder=1)

    for p_, marker, msz in zip(p, markers, markersizes):
        plt.scatter(p_[0, okp], p_[1, okp], msz, pid[okp],
                    cmap=cmap__, linewidths=2, marker=marker, zorder=2,
                    vmin=0., vmax=1.)
        if plot_point_order:
            for ii in np.where(okp)[0]:
                plt.text(p_[0, ii], p_[1, ii], '%d' %
                         ii, fontsize=int(msz*0.25))

    if bbox is not None:
        import matplotlib.patches as patches
        # Create a Rectangle patch
        rect = patches.Rectangle((bbox[0], bbox[1]), bbox[2], bbox[3],
                                 linewidth=1, edgecolor='r', facecolor='none')
        plt.gca().add_patch(rect)

    if im is None:
        plt.gca().invert_yaxis()
        plt.axis('equal')
        plt.gca().axes.get_xaxis().set_visible(False)
        plt.gca().axes.get_yaxis().set_visible(False)
        # plt.gca().set_frame_on(False)
        plt.gca().set_axis_off()
    else:  # remove all margins
        plt.gca().axes.get_xaxis().set_visible(False)
        plt.gca().axes.get_yaxis().set_visible(False)
        plt.gca().set_frame_on(False)
        plt.gca().set_axis_off()

    # return fig
    improj = np.array(fig2data(fig))
    if visdom_env is not None:
        viz = get_visdom_connection()
        viz.image(np.array(improj).transpose(2, 0, 1),
                  env=visdom_env, opts={'title': title}, win=visdom_win)

    plt.close(fig)

    return improj