示例#1
0
 def __radd__(self, gg):
     gg = deepcopy(gg)
     if self.name:
         gg.ylab = self.name.title()
     if self.labels and self.labels in LABEL_FORMATS:
         format_func = LABEL_FORMATS[self.labels]
         gg.ytick_formatter = FuncFormatter(format_func)
     if self.limits:
         gg.ylimits = self.limits
     if self.breaks:
         gg.ybreaks = self.breaks
     return gg
示例#2
0
t_MMST, p1_MMST, p2_MMST = get_popu_data(path+"traj_MultiEh.txt")

xs = [t_MMST /np.pi, t_QM / np.pi]
y1s = [p1_MMST, p1_QM]
y2s = [p2_MMST, p2_QM]

labels = ["MMST", "QM"]
colors1 = ["r--", "k--"]
colors2 = ["r", "k"]

ax = clp.initialize(col=1, row=1, width=4.3, fontsize=12, LaTeX=True)

clp.plotone(xs, y1s, ax, colors=colors1, alphaspacing=0.0, lw=2)
clp.plotone(xs, y2s, ax, labels=labels, colors=colors2, xlabel="time ($t$)",
            ylabel="Electronic population", alphaspacing=0.0, lw=2)

# Plot x-axis as a function of PI
def format_func(value, tick_number):
    # find number of multiples of pi/2
    N = value
    if N == 0:
        return "0"
    else:
        return r"${0}\pi$".format(N)

ax.xaxis.set_major_formatter(FuncFormatter(format_func))

# output figure
clp.adjust(tight_layout=True, savefile="SE_popu_MMST.pdf")
        for k in range(2):
            clp.plotone(X,
                        Y,
                        axes[k, j],
                        colors=['r', "k--", "c-."],
                        labels=["MMST", "QM", "coarse-grained MMST"] if
                        (i == 0 and j == 0) else None,
                        alphaspacing=0.01,
                        ylim=[-0.2, 12],
                        showlegend=True if (j == 0 and k == 0) else False,
                        xlim=None if k == 0 else [0.9622, 1.0378])
    axes[0, j].set_title(methods[j])
    axes[1, j].set_xlabel("Cavity position")
    if j is 0:
        for k in range(2):
            axes[k, j].set_ylabel("E-field Intensity (arbi. units)")
    axes[0, j].xaxis.set_major_formatter(FuncFormatter(format_func))
    axes[1, j].xaxis.set_major_formatter(FuncFormatter(format_func))

# Add arrow
axes[0, -1].text(2.25, 5.0, 'time increment', rotation=90, color='b', size=12)
#axes[1, -1].text(2.25, 5.0, 'time increment', rotation=90, color='b', size=12)
for k in range(2):
    axes[k, -1].annotate('',
                         xy=(1.05, 0.0),
                         xycoords='axes fraction',
                         xytext=(1.05, 1.0),
                         arrowprops=dict(arrowstyle="<-", color='b'))
#ax.grid(True, linestyle='--')
clp.adjust(tight_layout=True, savefile="EM_compare_MMST.pdf")
示例#4
0
    def plot_tau_preview(self, on_id="on", off_id="off", pyrlevel=2):
        """Plot a preview of current tau_on, tau_off and AA images.

        AA is plotted twice in 1st row of subplots in 2 diffent value ranges.

        :param str on_id: string ID of onband filter ("on")
        :param str off_id: string ID of offband filter ("off")
        :param pyrlevel: provide any integer here to reduce the image
            sizes using a gaussian pyramide approach (2)
        """
        lists = {}
        tm = {on_id: 1, off_id: 1}

        def fmt(num):
            return '{:.1e}'.format(num)

        for list_id in [on_id, off_id]:
            try:
                l = self.get_list(list_id)
                lists[list_id] = l
                if not l.bg_model.ready_2_go():
                    print("Tau preview could not be plotted, bg model is not "
                          " ready for filter: %s" % list_id)
                    return 0
                if not l.tau_mode:
                    tm[list_id] = 0
                    l.activate_tau_mode()
            except BaseException:
                print(format_exc())
                return 0
        fig, axes = subplots(2, 2, figsize=(16, 10))
        tau_on = lists[on_id].current_img().pyr_down(pyrlevel)
        t_on_str = lists[on_id].current_time_str()
        tau_off = lists[off_id].current_img().pyr_down(pyrlevel)
        t_off_str = lists[off_id].current_time_str()
        aa = tau_on - tau_off  # AA image object
        tau_max = max([tau_on.img.max(), tau_off.img.max(), aa.img.max()])
        tau_min = max([tau_on.img.min(), tau_off.img.min(), aa.img.min()])
        # make a color map for the index range
        cmap = shifted_color_map(tau_min, tau_max)

        im = axes[0, 0].imshow(tau_on.img,
                               cmap=cmap,
                               vmin=tau_min,
                               vmax=tau_max)
        fig.colorbar(im, ax=axes[0, 0], format=FuncFormatter(fmt))
        axes[0, 0].set_title("tau on: %s" % t_on_str)
        im = axes[0, 1].imshow(tau_off.img,
                               cmap=cmap,
                               vmin=tau_min,
                               vmax=tau_max)
        fig.colorbar(im, ax=axes[0, 1], format=FuncFormatter(fmt))
        axes[0, 1].set_title("tau off: %s" % t_off_str)
        im = axes[1, 0].imshow(aa.img, cmap=cmap, vmin=tau_min, vmax=tau_max)
        fig.colorbar(im, ax=axes[1, 0], format=FuncFormatter(fmt))
        axes[1, 0].set_title("AA (vals scaled)")
        cmap = shifted_color_map(aa.img.min(), aa.img.max())
        im = axes[1, 1].imshow(aa.img, cmap=cmap)
        fig.colorbar(im, ax=axes[1, 1], format=FuncFormatter(fmt))
        axes[1, 1].set_title("AA")
        tight_layout()
        for k, v in six.iteritems(tm):
            lists[k].activate_tau_mode(v)
        return axes