Esempio n. 1
0
    def plot_graph(self, fit_objective):
        plt.subplot(self.gs[0])
        y_min = None
        y_max = None
        for i_dataset in range(0, fit_objective.fitObjectCount()):
            # retrieving data from fit suite
            real_data = fit_objective.experimentalData(i_dataset).data()
            sim_data = fit_objective.simulationResult(i_dataset).data()

            # data values
            sim_values = sim_data.getArray()
            real_values = real_data.getArray()

            # default font properties dictionary to use
            font = {'family': 'serif',
                    'weight': 'normal',
                    'size': label_fontsize}


            plt.semilogy(sim_data.getAxis(0).getBinCenters(), sim_values, 'b',
                         real_data.getAxis(0).getBinCenters(), real_values, 'k--')
            if y_min is None or y_min > 0.5 * np.min(real_values):
                y_min = 0.5 * np.min(real_values)
            if y_max is None or y_max < 5 * np.max(real_values):
                y_max = 5 * np.max(real_values)
            plt.ylim((y_min, y_max))

            xlabel = ba.get_axes_labels(fit_objective.experimentalData(i_dataset), ba.AxesUnits.DEFAULT)[0]
            plt.legend(['BornAgain', 'Reference'], loc='upper right', prop=font)
            plt.xlabel(xlabel, fontdict=font)
            plt.ylabel("Intensity", fontdict=font)
            plt.title("Specular data fitting", fontdict=font)
def plot_result(sim_result, ref_result, bin_start=0, bin_end=-1):
    """
    Plots the graphs of obtained simulation data
    """
    sim_data = sim_result.array()
    ref_data = ref_result.array()

    plt.semilogy(
        get_real_data_axis(bin_start, bin_end) * 180 / np.pi,
        get_real_data_values(bin_start, bin_end), sim_result.axis(), sim_data,
        ref_result.axis(), ref_data)

    xlabel = ba.get_axes_labels(sim_result, ba.AxesUnits.DEFAULT)[0]
    ylabel = "Intensity"
    plt.xlabel(xlabel, fontsize=16)
    plt.ylabel(ylabel, fontsize=16)
    plt.legend(['Experimental data', 'Simulation', 'Reference'],
               loc='upper right',
               fontsize=16)

    plt.show()
Esempio n. 3
0
def plot(fontsize=16):
    """
    Creates 4 plots: 2D experiment, 2D simulation, slice along Qz and slice along Qy
    """
    plt.style.use('seaborn-talk')
    matplotlib.rcParams['xtick.labelsize'] = fontsize
    matplotlib.rcParams['ytick.labelsize'] = fontsize
    data = load_data()
    plt.figure(figsize=(22, 17))
    zmin = 0.1
    zmax = 2.0e+06
    qz_slice = 0.4
    qy_slice = 0.64
    # ====================
    # Experiment 2D
    # ====================
    plt.subplot(2, 2, 1)
    ba.plot_colormap(data, units=ba.AxesUnits.QSPACE, zmin=zmin, zmax=zmax)
    plt.axhline(y=qz_slice, color='0.5', linestyle='--', linewidth=1)
    plt.axvline(x=qy_slice, color='0.5', linestyle='--', linewidth=1)
    plt.title("Experiment", fontsize=fontsize)
    # ax.tick_params(axis='both', which='major', labelsize=fontsize)
    # ====================
    # Simulation 2D
    # ====================
    result = run_simulation()
    axes_labels = ba.get_axes_labels(result, ba.AxesUnits.QSPACE)
    plt.subplot(2, 2, 2)
    ba.plot_colormap(result, units=ba.AxesUnits.QSPACE, zmin=zmin, zmax=zmax)
    plt.axhline(y=qz_slice, color='0.5', linestyle='--', linewidth=1)
    plt.axvline(x=qy_slice, color='0.5', linestyle='--', linewidth=1)
    plt.title("BornAgain simulation", fontsize=fontsize)
    # ====================
    # projection along Qz
    # ====================
    plt.subplot(2, 2, 3)
    exp_qz = data.histogram2d(ba.AxesUnits.QSPACE).projectionY(qy_slice)
    sim_qz = result.histogram2d(ba.AxesUnits.QSPACE).projectionY(qy_slice)
    plt.semilogy(exp_qz.getBinCenters(),
                 exp_qz.getBinValues(),
                 color='k',
                 marker='.',
                 markersize=5,
                 linestyle='None',
                 label="Experiment")
    plt.semilogy(sim_qz.getBinCenters(),
                 sim_qz.getBinValues(),
                 color='g',
                 linewidth=2,
                 label="Simulation")
    # plt.xlim(0.1, 1.21)    # uncomment and edit to set x axis limits
    # plt.ylim(0.5, zmax)    # uncomment and edit to set y axis limits
    plt.xlabel(axes_labels[1], fontsize=fontsize)
    plt.ylabel(r'$\mathrm{I(Q_z)}$, a.u.', fontsize=fontsize)
    plt.legend(fontsize=fontsize)
    plt.title(r"Slice along $Q_z$", fontsize=fontsize)
    # =====================
    # projection along Qy
    # =====================
    plt.subplot(2, 2, 4)
    exp_qy = data.histogram2d(ba.AxesUnits.QSPACE).projectionX(qz_slice)
    sim_qy = result.histogram2d(ba.AxesUnits.QSPACE).projectionX(qz_slice)
    plt.semilogy(exp_qy.getBinCenters(),
                 exp_qy.getBinValues(),
                 color='k',
                 marker='.',
                 markersize=5,
                 linestyle='None',
                 label="Experiment")
    plt.semilogy(sim_qy.getBinCenters(),
                 sim_qy.getBinValues(),
                 color='g',
                 linewidth=2,
                 label="Simulation")
    # plt.xlim(-0.81, 0.71)        # uncomment and edit to set x axis limits
    # plt.ylim(0.5, zmax)          # uncomment and edit to set y axis limits
    plt.xlabel(axes_labels[0], fontsize=fontsize)
    plt.ylabel(r'$\mathrm{I(Q_y)}$, a.u.', fontsize=fontsize)
    plt.legend(fontsize=fontsize)
    plt.title(r"Slice along $Q_y$", fontsize=fontsize)

    # plt.savefig("{}.png".format("my_meso"))   # uncomment to save figure

    # uncomment to save slices to text files
    # np.savetxt("{}_slice_qz.txt".format("my_meso"), np.column_stack([sim_qz.getBinCenters(), sim_qz.getBinValues()]))
    # np.savetxt("{}_slice_qy.txt".format("my_meso"), np.column_stack([sim_qy.getBinCenters(), sim_qy.getBinValues()]))

    plt.show()