예제 #1
0
def show_fig_standard_curve(fig,
                            W,
                            c,
                            grad_g,
                            N,
                            theta,
                            show_grad=True,
                            show_background=True,
                            clear=True,
                            timing=0.1):
    ax = fig.add_subplot(111)
    cplot(c)
    if show_grad:
        plt.quiver(np.real(c),
                   np.imag(c),
                   -np.real(grad_g),
                   -np.imag(grad_g),
                   color='blue',
                   alpha=0.5)
    if show_background:
        imageplot(np.transpose(W))
    fig.canvas.draw()  # draw
    if clear:
        time.sleep(timing)  # sleep
    fig.show()
    if clear:
        fig.clear()
예제 #2
0
def plot_dictionary(D, title='Dictionary'):
    ''' Plot a dictionary of shape (width*width, n_atoms) '''
    # Check that D.shape == (width*width, n_atoms)
    assert len(D.shape) == 2
    assert int(np.sqrt(D.shape[0]))**2 == D.shape[0]
    (signal_size, n_atoms) = D.shape
    width = int(np.sqrt(D.shape[0]))
    D = D.reshape((width, width, n_atoms))
    n = int(np.ceil(np.sqrt(n_atoms)))  # Size of the plot in number of atoms

    # Pad the atoms
    pad_size = 1
    missing_atoms = n**2 - n_atoms

    padding = (((pad_size, pad_size), (pad_size, pad_size), (0,
                                                             missing_atoms)))
    D = np.pad(D, padding, mode='constant', constant_values=1)
    padded_width = width + 2 * pad_size
    D = D.reshape(padded_width, padded_width, n, n)
    D = D.transpose(2, 0, 3, 1)  # Needed for the reshape
    big_image_size = n * padded_width
    D = D.reshape(big_image_size, big_image_size)
    plt.figure(figsize=(8, 12))
    imageplot(D)
    plt.title(title)
    plt.show()
예제 #3
0
def plot_levelset(Z, level=0, f=[]):
    """
        f is supposed to be of the same shape as Z
    """
    if len(f) == 0:
        f = np.copy(Z)
        
    n,p = np.shape(Z)
    X,Y = np.meshgrid(np.arange(0,n),np.arange(0,p))
    plt.contour(X, Y, Z,[level],linewidths=2, colors="red")
    imageplot(f)
예제 #4
0
def plot_levelset(Z, level=0, f=[]):
    """
        f is supposed to be of the same shape as Z
    """
    if len(f) == 0:
        f = np.copy(Z)

    n, p = np.shape(Z)
    X, Y = np.meshgrid(np.arange(0, n), np.arange(0, p))
    plt.contour(X, Y, Z, [level], linewidths=2, colors="red")
    imageplot(f)
예제 #5
0
def show_fig_polar_curve(fig, c, W, **kwargs):
    """

    :param fig:
    :param c:
    :param W:
    :param kwargs:
    :return:
    """
    if 'c_r' in kwargs:
        ax1 = fig.add_subplot(2, 2, 1)
        ax1.set_title('Composante radiale du contour')
        ax1.plot(kwargs['theta'], -kwargs['c_r'])
        # plt.axhline(y=0, color='r', linestyle='-')
        ax1.set_xlabel(r"$ \theta $")
        ax1.xaxis.set_major_formatter(plt.FuncFormatter(format_func))

    if 'c_r' in kwargs:
        ax3 = fig.add_subplot(2, 2, 3)
        fft = np.fft.fft(kwargs['c_r'])
        ax3.plot(np.abs(fft)[:int(len(fft) / 2)])
        ax3.set_yscale('log')
        ax3.set_title(
            'Coefficients de Fourier de la componsante radiale  \n du contour')
        ax3.set_xlabel(r"$\omega$")

    ax2 = fig.add_subplot(2, 2, 2)
    ax2.set_title('Gradients le long du contour')
    cplot(c)

    if 'c_0' in kwargs:
        plt.scatter(np.real(kwargs['c_0']), np.imag(kwargs['c_0']))

    show_grad_c0 = True if 'show_grad_c0' in kwargs else False
    show_grad_cr = True if 'show_grad_cr' in kwargs else False
    show_background = True if 'show_background' in kwargs else False

    if show_grad_c0 and 'c_0' in kwargs and 'ct_0' in kwargs:
        plt.quiver(np.real(kwargs['c_0']),
                   np.imag(kwargs['c_0']),
                   -np.real(kwargs['ct_0']),
                   np.imag(kwargs['ct_0']),
                   label=r"gradient $c_o$",
                   alpha=0.5,
                   color='green')
    if show_grad_cr and 'ct_r' in kwargs and 'N' in kwargs:
        plt.quiver(np.real(c),
                   np.imag(c),
                   -kwargs['ct_r'] * np.real(kwargs['N']),
                   kwargs['ct_r'] * np.imag(kwargs['N']),
                   label=r"gradient $c_r$",
                   alpha=0.5,
                   color='blue')

    if show_background:
        imageplot(np.transpose(W))
    plt.legend()

    ax4 = fig.add_subplot(2, 2, 4)
    ax4.set_title('Contour')
    cplot(c)
    if show_background:
        imageplot(np.transpose(W))

    fig.canvas.draw()  # draw
    clear = True if 'clear' in kwargs else False
    save = True if 'save' in kwargs else False
    save_contour = True if 'save_contour' in kwargs else False

    if save_contour:
        extent = ax4.get_window_extent().transformed(
            fig.dpi_scale_trans.inverted())
        fig.savefig('{}.eps'.format(kwargs['save_contour']),
                    bbox_inches=extent.expanded(1.3, 1.3))

    if save:
        if 'iter' in kwargs:
            plt.savefig('{}_{}.eps'.format(kwargs['save'],
                                           str(kwargs['iter'])),
                        quality=100)

        else:
            plt.savefig('{}.eps'.format(kwargs['save']), quality=100)

    if clear and 'timing' in kwargs:
        time.sleep(kwargs['timing'])  # sleep
        fig.show()
        fig.clear()
    else:
        fig.show()