Пример #1
0
def plot_distribution(E, H, nx, x, lamda, filename):

    rgb = w2rgb.wavelength_to_rgb(lamda * 1e9, gamma=1)
    plt.rcParams.update({'font.size': 18})
    fig, ax1 = plt.subplots(figsize=(10.0, 4.0))
    ax1.plot(np.asarray(x) / 1e-9, E, color=rgb, linewidth=3, label='$|E|^2$')
    ax1.plot(np.asarray(x) / 1e-9,
             H,
             color='gray',
             linewidth=2,
             linestyle='--',
             label='$|H|^2$')
    ax1.set_ylim(0)
    plt.legend()
    ax2 = ax1.twinx()
    nx = np.squeeze(nx)
    ax2.fill_between(np.asarray(x) / 1e-9,
                     np.squeeze(np.abs(nx)),
                     np.zeros(len(nx)) + np.min(np.abs(nx)) - 0.1,
                     color='cy')
    ax2.set_ylim(np.min(np.abs(nx)) - 0.1, np.max(np.abs(nx) + 0.5))
    ax1.set_xlabel('distance [nm]')
    ax1.set_ylabel('normalized [a.u.]')
    ax2.set_ylabel('refractive index', color=(0, 0.8, 0.8))
    plt.xlim(x[0] / 1e-9, x[-1] / 1e-9)
    plt.title('$\lambda : $' + str(np.around(lamda * 1e9, 3)) + ' nm')
    plt.tight_layout()
    ax1.set_zorder(ax2.get_zorder() + 1)
    ax1.patch.set_visible(False)

    plt.savefig(filename + '.png')
    mf.save_fig(fig, filename)
    plt.clf()
Пример #2
0
def read_and_plot_refractive_index_spectrum(filename):

    # this method reads a specific file format for refractive index spectrum.
    # it has the following format

    # line 1: (it is passed - you can put here any comments you have)
    # line 2: 0.5, 1, 1 (the first element is wavelength in um and the 2nd and 3rd is real and imag  of refractive index)
    # ...
    #(this is the format given by the website for .csv file : https://refractiveindex.info/)
    # be careful : some data donot have real and imaginary in the same wavelength. You need to prepare the file accordingly.

    f = open(filename)
    name = filename.split('\\')[-1]
    name = name.split('.')[0]
    f = open(filename)
    f.readline()
    mat_lamda = []
    mat_n = []
    complex_n = True
    for line in f:
        mat_lamda.append(np.float(line.split(',')[0]) * 1e-6)
        try:
            mat_n.append(
                np.float(line.split(',')[1]) +
                1j * np.float(line.split(',')[2]))
        except IndexError:
            mat_n.append(np.float(line.split(',')[1]))
            complex_n = False
    mat_lamda = np.asarray(mat_lamda)

    plt.rcParams.update({'font.size': 15})
    fig, ax = plt.subplots(figsize=(6.0, 4.0))
    plt.plot(mat_lamda / 1e-9,
             np.real(mat_n),
             '-o',
             color='darkred',
             linewidth=3,
             label='$n$')
    if complex_n:
        plt.plot(mat_lamda / 1e-9,
                 np.imag(mat_n),
                 '-o',
                 color='k',
                 linewidth=3,
                 label='$\kappa$')
    # #fmat = interp1d(mat_lamda, mat_n)
    # plt.plot(np.linspace(mat_lamda[0],mat_lamda[-1],1000)/1e-9,np.imag(fmat(np.linspace(mat_lamda[0],mat_lamda[-1],1000))), '-o')
    plt.xlim(mat_lamda[0] / 1e-9, mat_lamda[-1] / 1e-9)
    plt.grid()
    plt.xlabel('wavelength [nm]')
    plt.ylabel("refractive index $n_{c} = n + j \kappa$")
    plt.title(name)
    plt.legend()
    plt.tight_layout()
    mf.save_fig(fig, '..\\PLOTS\\refractive_indices\\' + name)
    n_mat = [mat_lamda, mat_n]
    return n_mat
Пример #3
0
def plot_spectrum(T, R, lamdas, filename):

    # T = np.asarray(T)
    plt.rcParams.update({'font.size': 18})
    fig, ax = plt.subplots(figsize=(6.0, 4.0))
    plt.grid(zorder=20)
    plt.plot(lamdas / 1e-9, T, 'darkred', linewidth=2)
    plt.fill_between(lamdas / 1e-9,
                     T,
                     np.zeros(len(T)),
                     color='darkred',
                     linewidth=2,
                     zorder=10,
                     label='T')
    plt.plot(lamdas / 1e-9, R + T, 'k', linestyle='--', label='T + R')
    plt.xlim(lamdas[0] / 1e-9, lamdas[-1] / 1e-9)
    plt.xlabel('wavelength [nm]')
    plt.ylabel('normalized intenstiy')
    #plt.legend(loc = 'best')#,  bbox_to_anchor=(1.5, 1, 0, 0) )
    plt.ylim(0, 1 + 0.05)
    plt.tight_layout()

    plt.savefig(filename + 'T.png')
    mf.save_fig(fig, filename + 'T')
    plt.clf()

    plt.rcParams.update({'font.size': 18})
    fig, ax = plt.subplots(figsize=(6.0, 4.0))
    plt.grid(zorder=20)
    plt.plot(lamdas / 1e-9, R, 'darkgreen', linewidth=2)
    plt.fill_between(lamdas / 1e-9,
                     R,
                     np.zeros(len(T)),
                     color='darkgreen',
                     linewidth=2,
                     zorder=10,
                     label='R')
    # plt.plot(lamdas/1e-9, R+T ,'k',linestyle = '--', label = 'T + R')
    plt.xlim(lamdas[0] / 1e-9, lamdas[-1] / 1e-9)
    plt.xlabel('wavelength [nm]')
    plt.ylabel('normalized intensity')
    # plt.legend(loc = 'best')#,  bbox_to_anchor=(1.5, 1, 0, 0) )
    plt.ylim(0, 1 + 0.05)
    plt.tight_layout()

    plt.savefig(filename + 'R.png')
    mf.save_fig(fig, filename + 'R')
    plt.clf()