예제 #1
0
def interpret_data_with_SequenceDNN(dnn, simulation_data):
    # get a positive and a negative example from the simulation data
    pos_indx = np.flatnonzero(simulation_data.y_valid == 1)[2]
    neg_indx = np.flatnonzero(simulation_data.y_valid == 0)[2]
    pos_X = simulation_data.X_valid[pos_indx:pos_indx + 1]
    neg_X = simulation_data.X_valid[neg_indx:neg_indx + 1]
    # get motif scores, ISM scores, and DeepLIFT scores
    scores_dict = defaultdict(OrderedDict)
    scores_dict['Positive']['Motif Scores'] = get_motif_scores(
        pos_X, simulation_data.motif_names)
    scores_dict['Positive']['ISM Scores'] = dnn.in_silico_mutagenesis(
        pos_X).max(axis=-2)
    scores_dict['Positive']['DeepLIFT Scores'] = dnn.deeplift(pos_X).max(
        axis=-2)
    scores_dict['Negative']['Motif Scores'] = get_motif_scores(
        neg_X, simulation_data.motif_names)
    scores_dict['Negative']['ISM Scores'] = dnn.in_silico_mutagenesis(
        neg_X).max(axis=-2)
    scores_dict['Negative']['DeepLIFT Scores'] = dnn.deeplift(neg_X).max(
        axis=-2)

    # get motif site locations
    # motif_sites = {}
    # motif_sites['Positive'] = [np.argmax(scores_dict['Positive']['Motif Scores'][0, i, :])
    #                            for i in range(len(simulation_data.motif_names))]
    # motif_sites['Negative'] = [np.argmax(scores_dict['Negative']['Motif Scores'][0, i, :])
    #                            for i in range(len(simulation_data.motif_names))]
    motif_sites = {
        key: [
            embedded_motif.startPos + len(embedded_motif.what.string) // 2
            for embedded_motif in
            (next(embedded_motif
                  for embedded_motif in simulation_data.valid_embeddings[index]
                  if isinstance(embedded_motif.what, StringEmbeddable)
                  and motif_name in embedded_motif.what.stringDescription)
             for motif_name in simulation_data.motif_names)
        ]
        for key, index in (('Positive', pos_indx), ('Negative', neg_indx))
    }
    # organize legends
    motif_label_dict = {}
    motif_label_dict['Motif Scores'] = simulation_data.motif_names
    if len(simulation_data.motif_names) == dnn.num_tasks:
        motif_label_dict['ISM Scores'] = simulation_data.motif_names
    else:
        motif_label_dict['ISM Scores'] = [
            '_'.join(simulation_data.motif_names)
        ]
    motif_label_dict['DeepLIFT Scores'] = motif_label_dict['ISM Scores']
    # plot scores and highlight motif site locations
    seq_length = pos_X.shape[-1]
    plots_per_row = 2
    plots_per_column = 3
    ylim_dict = {
        'Motif Scores': (-80, 30),
        'ISM Scores': (-1.5, 3.0),
        'DeepLIFT Scores': (-1.5, 3.0)
    }
    motif_colors = ['b', 'r', 'c', 'm', 'g', 'k', 'y']
    font_size = 12
    num_x_ticks = 5
    highlight_width = 5
    motif_labels_cache = []

    f = plt.figure(figsize=(10, 12))
    f.subplots_adjust(hspace=0.15, wspace=0.15)
    f.set_tight_layout(True)

    for j, key in enumerate(['Positive', 'Negative']):
        for i, (score_type, scores) in enumerate(scores_dict[key].items()):
            ax = f.add_subplot(plots_per_column, plots_per_row,
                               plots_per_row * i + j + 1)
            ax.set_ylim(ylim_dict[score_type])
            ax.set_xlim((0, seq_length))
            ax.set_frame_on(False)
            if j == 0:  # put y axis and ticks only on left side
                xmin, xmax = ax.get_xaxis().get_view_interval()
                ymin, ymax = ax.get_yaxis().get_view_interval()
                ax.add_artist(
                    Line2D((xmin, xmin), (ymin, ymax),
                           color='black',
                           linewidth=2))
                ax.get_yaxis().tick_left()
                for tick in ax.yaxis.get_major_ticks():
                    tick.label.set_fontsize(font_size / 1.5)
                ax.set_ylabel(score_type)
            if j > 0:  # remove y axes
                ax.get_yaxis().set_visible(False)
            if i < (plots_per_column - 1):  # remove x axes
                ax.get_xaxis().set_visible(False)
            if i == (plots_per_column - 1):  # set x axis and ticks on bottom
                ax.set_xticks(seq_length / num_x_ticks *
                              (np.arange(num_x_ticks + 1)))
                xmin, xmax = ax.get_xaxis().get_view_interval()
                ymin, ymax = ax.get_yaxis().get_view_interval()
                ax.add_artist(
                    Line2D((xmin, xmax), (ymin, ymin),
                           color='black',
                           linewidth=2))
                ax.get_xaxis().tick_bottom()
                for tick in ax.xaxis.get_major_ticks():
                    tick.label.set_fontsize(font_size / 1.5)
                ax.set_xlabel("Position")
            if j > 0 and i < (plots_per_column - 1):  # remove all axes
                ax.axis('off')

            add_legend = False
            for _i, motif_label in enumerate(motif_label_dict[score_type]):
                if score_type == 'Motif Scores':
                    scores_to_plot = scores[0, _i, :]
                else:
                    scores_to_plot = scores[0, 0, 0, :]
                if motif_label not in motif_labels_cache:
                    motif_labels_cache.append(motif_label)
                    add_legend = True
                motif_color = motif_colors[motif_labels_cache.index(
                    motif_label)]
                ax.plot(scores_to_plot, label=motif_label, c=motif_color)
            if add_legend:
                leg = ax.legend(loc=[0, 0.85],
                                frameon=False,
                                fontsize=font_size,
                                ncol=3,
                                handlelength=-0.5)
                for legobj in leg.legendHandles:
                    legobj.set_color('w')
                for _j, text in enumerate(leg.get_texts()):
                    text_color = motif_colors[motif_labels_cache.index(
                        motif_label_dict[score_type][_j])]
                    text.set_color(text_color)
            for motif_site in motif_sites[key]:
                ax.axvspan(motif_site - highlight_width,
                           motif_site + highlight_width,
                           color='grey',
                           alpha=0.1)
plt.xticks([])
plt.title('Approximate Entropy (Lines)')
plt.show()
"""

plt.figure(figsize=(4,6))
plt.plot(np.zeros(np.shape(app_en_healthy)), app_en_healthy, 'g*')
plt.plot(np.zeros(np.shape(app_en_tremor)), app_en_tremor, 'ro')
plt.tick_params(
    axis='x',          # changes apply to the x-axis
    which='both',      # both major and minor ticks are affected
    bottom=False,      # ticks along the bottom edge are off
    top=False,         # ticks along the top edge are off
    labelbottom=False) # labels along the bottom edge are off
plt.title('Approximate Entropy (Spirals)')
legend_elements = [Line2D([0], [0], marker='*', color='w', label='Healthy',
                          markerfacecolor='g', markersize=10),
                   Line2D([0], [0], marker='o', color='w', label='Tremor',
                          markerfacecolor='r', markersize=7)]

plt.legend(handles=legend_elements, loc='upper left')

#plt.legend((app_en_healthy, app_en_tremor),('Healthy', 'Tremor'), numpoints=1, loc='upper left', ncol=3, fontsize=8)
plt.show()

#%%
import matplotlib.pyplot as plt
"""
plt.plot(svd_en_healthy,'g*', svd_en_tremor, 'ro')
plt.xticks([])
plt.title('Singular Value Decomposition')
plt.show()
예제 #3
0
if period:
    ax.set_ylabel('LFP period (s)')
else:
    ax.set_ylabel('LFP frequency (Hz)')
ax.set_xlim(0, 3)
ax.set_ylim(4, 10)

ax1.set_xlabel('Virtual speed (m/s)', fontsize=16)
if period:
    ax1.set_ylabel('LFP period (s)', fontsize=16)
else:
    ax1.set_ylabel('LFP frequency (Hz)', fontsize=16)
ax1.set_xlim(0, 3)
ax1.set_ylim(4, 10)

cl1_line = Line2D((0, 1), (0, 0), color=c_05, lw=7)
cl2_line = Line2D((0, 1), (0, 0), color=c_15, lw=7)
fig.legend((cl1_line, cl2_line), ("Gain = 0.5", "Gain = 1.5"),
           numpoints=1,
           loc="best",
           fontsize=15,
           frameon=False)
fig1.legend((cl1_line, cl2_line), ("Gain = 0.5", "Gain = 1.5"),
            numpoints=1,
            loc="best",
            fontsize=15,
            frameon=False)

print 'average gain 0.5 speed in treadmill coordinates: ', numpy.average(
    speeds_real05)
print 'average gain 1.5 speed in treadmill coordinates: ', numpy.average(
                yvalues.append(np.nan)
                ylo_values.append(np.nan)
                yhi_values.append(np.nan)
            else:
                yvalues.append(current_triplet[0])
                ylo_values.append(current_triplet[1])
                yhi_values.append(current_triplet[2])

        print(yvalues)

        if def_name == 'none':
            ax1.plot([0, 0], [ylo_values[0], yhi_values[0]], marker='.', color='C{:d}'.format(i_col))
            ax1.plot([-0.0002, 0.0002], [yhi_values[0], yhi_values[0]], color='C{:d}'.format(i_col))
            ax1.plot([-0.0002, 0.0002], [ylo_values[0], ylo_values[0]], color='C{:d}'.format(i_col))
        else:
            ax1.plot(fpr_list, yvalues, color='C{:d}'.format(i_col), marker='.', linestyle='-')
            ax1.fill_between(fpr_list, ylo_values, yhi_values, color='C{:d}'.format(i_col), alpha=0.2)

    legend2 = Legend(ax1, [Line2D([0], [0], marker='.', color='C{:d}'.format(i)) for i in [2, 0, 1]], ['No defense', 'CLRZ', 'OSSE'],
                     loc='lower left', title='Defense')
    ax1.add_artist(legend2)
    # plt.xticks(list(range(len(offset_list))), offset_list, fontsize=12)
    ax1.set_ylim([0, 1.01])
    ax1.set_ylabel('Attack Accuracy', fontsize=14)
    ax1.set_xlabel("False Positive Rate", fontsize=14)
    plt.tight_layout()
    plt.savefig(plots_path + '/' + 'performance_graphm_sm.pdf')
    plt.show()


예제 #5
0
def plot_all_data(checkpoints_data: list):
    legend_elements = [
        Line2D([0], [0],
               linestyle='-.',
               color='black',
               alpha=.5,
               lw=2,
               label='Bilinear'),
        Line2D([0], [0],
               linestyle=':',
               color='black',
               alpha=.5,
               lw=2,
               label='Decoder'),
        Line2D([0], [0],
               linestyle='-',
               color='black',
               alpha=.5,
               lw=2,
               label='Total')
    ]
    legend1 = plt.legend(handles=legend_elements,
                         loc='upper left',
                         fancybox=True,
                         framealpha=0.5)

    ax = plt.gca()

    for checkpoint_name, checkpoint_data in checkpoints_data:
        x_indices = list(range(len(checkpoint_data)))
        saliency_loss, decoder_loss, total_loss = zip(*checkpoint_data)

        color = next(ax._get_lines.prop_cycler)['color']

        # Uncomment to name the labels in the legend
        # compare_occ
        #    if checkpoint_name == "batch64_hid256_emb100_meroracle_min9_bilinTrue_alpha0.5":
        #      checkpoint_name = "9+ occurrence"
        #    elif checkpoint_name == "batch64_hid256_emb100_meroracle_min500_bilinTrue_alpha0.5":
        #      checkpoint_name = "500+ occurrence"

        # compare_alpha_batch
        #    if checkpoint_name == "batch64_hid256_emb100_meroracle_min9_bilinTrue_alpha0.5":
        #      checkpoint_name = "Batch 64, alpha 0.5"
        #    elif checkpoint_name == "batch64_hid256_emb100_meroracle_min9_bilinTrue_alpha0.7":
        #      checkpoint_name = "Batch 64, alpha 0.7"
        #    elif checkpoint_name == "batch64_hid256_emb100_meroracle_min9_bilinTrue_alpha0.99":
        #      checkpoint_name = "Batch 64, alpha 0.99"
        #    elif checkpoint_name == "batch4_hid256_emb100_meroracle_min9_bilinTrue_alpha0.5":
        #      checkpoint_name = "Batch 4, alpha 0.5"
        #    elif checkpoint_name == "batch4_hid256_emb100_meroracle_min9_bilinTrue_alpha0.7":
        #      checkpoint_name = "Batch 4, alpha 0.7"

        # compare_bilinear
        #    if checkpoint_name == "batch64_hid256_emb100_meroracle_min9_bilinTrue_alpha0.5":
        #      checkpoint_name = "With bilinear"
        #    elif checkpoint_name == "batch64_hid256_emb100_meroracle_min9_bilinFalse_alpha0.5":
        #      checkpoint_name = "Without bilinear"

        # compare_oracle_mixed
        #    if checkpoint_name == "batch64_hid256_emb100_meroracle_min9_bilinTrue_alpha0.5":
        #      checkpoint_name = "Oracle"
        #    elif checkpoint_name == "batch64_hid256_emb100_mermixed_min9_bilinTrue_alpha0.5":
        #      checkpoint_name = "Mixed"

        if max(total_loss) < 0:
            continue

        if max(saliency_loss) > 0:
            plt.plot(x_indices,
                     saliency_loss,
                     linestyle='-.',
                     color=color,
                     alpha=0.5)
            plt.plot(x_indices,
                     decoder_loss,
                     linestyle=':',
                     color=color,
                     alpha=0.5)
        plt.plot(x_indices,
                 total_loss,
                 label=checkpoint_name,
                 linestyle='-',
                 color=color,
                 alpha=0.5)

    plt.xlabel("Epochs")
    plt.ylabel("Loss")

    # Uncomment to change the order of the labels in the legend
    #  handles, labels = plt.gca().get_legend_handles_labels()
    #  order = [4,2,1,0,3]
    #  plt.legend([handles[idx] for idx in order],[labels[idx] for idx in order], fancybox=True, framealpha=0.4, loc='upper right')

    plt.legend(fancybox=True, framealpha=0.4, loc='upper right')
    plt.gca().add_artist(legend1)
    plt.show()
예제 #6
0
    def create_artists(self, legend, orig_handle, xdescent, ydescent, width,
                       height, fontsize, trans):

        plotlines, caplines, barlinecols = orig_handle

        xdata, xdata_marker = self.get_xdata(legend, xdescent, ydescent, width,
                                             height, fontsize)

        ydata = ((height - ydescent) / 2.) * np.ones(xdata.shape, float)
        legline = Line2D(xdata, ydata)

        xdata_marker = np.asarray(xdata_marker)
        ydata_marker = np.asarray(ydata[:len(xdata_marker)])

        xerr_size, yerr_size = self.get_err_size(legend, xdescent, ydescent,
                                                 width, height, fontsize)

        legline_marker = Line2D(xdata_marker, ydata_marker)

        # when plotlines are None (only errorbars are drawn), we just
        # make legline invisible.
        if plotlines is None:
            legline.set_visible(False)
            legline_marker.set_visible(False)
        else:
            self.update_prop(legline, plotlines, legend)

            legline.set_drawstyle('default')
            legline.set_marker('None')

            self.update_prop(legline_marker, plotlines, legend)
            legline_marker.set_linestyle('None')

            if legend.markerscale != 1:
                newsz = legline_marker.get_markersize() * legend.markerscale
                legline_marker.set_markersize(newsz)

        handle_barlinecols = []
        handle_caplines = []

        if orig_handle.has_xerr:
            verts = [((x - xerr_size, y), (x + xerr_size, y))
                     for x, y in zip(xdata_marker, ydata_marker)]
            coll = mcoll.LineCollection(verts)
            self.update_prop(coll, barlinecols[0], legend)
            handle_barlinecols.append(coll)

            if caplines:
                capline_left = Line2D(xdata_marker - xerr_size, ydata_marker)
                capline_right = Line2D(xdata_marker + xerr_size, ydata_marker)
                self.update_prop(capline_left, caplines[0], legend)
                self.update_prop(capline_right, caplines[0], legend)
                capline_left.set_marker("|")
                capline_right.set_marker("|")

                handle_caplines.append(capline_left)
                handle_caplines.append(capline_right)

        if orig_handle.has_yerr:
            verts = [((x, y - yerr_size), (x, y + yerr_size))
                     for x, y in zip(xdata_marker, ydata_marker)]
            coll = mcoll.LineCollection(verts)
            self.update_prop(coll, barlinecols[0], legend)
            handle_barlinecols.append(coll)

            if caplines:
                capline_left = Line2D(xdata_marker, ydata_marker - yerr_size)
                capline_right = Line2D(xdata_marker, ydata_marker + yerr_size)
                self.update_prop(capline_left, caplines[0], legend)
                self.update_prop(capline_right, caplines[0], legend)
                capline_left.set_marker("_")
                capline_right.set_marker("_")

                handle_caplines.append(capline_left)
                handle_caplines.append(capline_right)

        artists = []
        artists.extend(handle_barlinecols)
        artists.extend(handle_caplines)
        artists.append(legline)
        artists.append(legline_marker)

        for artist in artists:
            artist.set_transform(trans)

        return artists
    def render(self, mode='human', title=None):

        color_map = "gist_ncar"

        if title is None:
            title = self.env_id

        r, c = self.agent_location
        x2, y2 = 0, 0
        if self.agent_facing_str == 'NORTH':
            x2, y2 = 0, -0.01
        elif self.agent_facing_str == 'SOUTH':
            x2, y2 = 0, 0.01
        elif self.agent_facing_str == 'WEST':
            x2, y2 = -0.01, 0
        elif self.agent_facing_str == 'EAST':
            x2, y2 = 0.01, 0

        plt.figure(title, figsize=(9, 5))
        plt.imshow(self.map, cmap=color_map, vmin=0, vmax=len(self.items_id))
        plt.arrow(c, r, x2, y2, head_width=0.7, head_length=0.7, color='white')
        plt.title('NORTH', fontsize=10)
        plt.xlabel('SOUTH')
        plt.ylabel('WEST')
        plt.text(self.map_size, self.map_size // 2, 'EAST', rotation=90)
        # plt.colorbar()
        # plt.grid()

        info = '\n'.join([
            "               Info:             ",
            "Steps: " + str(self.step_count),
            "Agent Facing: " + self.agent_facing_str,
            "Action: " + self.last_action,
            "Selected item: " + self.selected_item,
            "Reward: " + str(self.last_reward),
            "Step Cost: " + str(self.last_step_cost),
            "Done: " + str(self.last_done)
        ])
        props = dict(boxstyle='round', facecolor='w', alpha=0.2)
        plt.text(-(self.map_size // 2) - 0.5,
                 2.25,
                 info,
                 fontsize=10,
                 bbox=props)  # x, y

        if self.last_done:
            if self.inventory_items_quantity[self.goal_item_to_craft] >= 1:
                you_win = "YOU WIN " + self.env_id + "!!!"
                you_win += "\nYOU CRAFTED " + self.goal_item_to_craft.upper(
                ) + "!!!"
                props = dict(boxstyle='round', facecolor='w', alpha=1)
                plt.text(0 - 0.1, (self.map_size // 2),
                         you_win,
                         fontsize=18,
                         bbox=props)
            else:
                you_win = "YOU DIED " + self.env_id + "!!!"
                props = dict(boxstyle='round', facecolor='w', alpha=1)
                plt.text(0 - 0.1, (self.map_size // 2),
                         you_win,
                         fontsize=18,
                         bbox=props)

        cmap = get_cmap(color_map)

        legend_elements = [
            Line2D([0], [0],
                   marker="^",
                   color='w',
                   label='agent',
                   markerfacecolor='w',
                   markersize=12,
                   markeredgewidth=2,
                   markeredgecolor='k'),
            Line2D([0], [0], color='w', label="INVENTORY:")
        ]
        for item in sorted(self.inventory_items_quantity):
            rgba = cmap(self.items_id[item] / len(self.items_id))
            legend_elements.append(
                Line2D([0], [0],
                       marker="s",
                       color='w',
                       label=item + ': ' +
                       str(self.inventory_items_quantity[item]),
                       markerfacecolor=rgba,
                       markersize=16))
        plt.legend(handles=legend_elements,
                   bbox_to_anchor=(1.55, 1.02))  # x, y

        plt.tight_layout()
        plt.pause(0.01)
        plt.clf()
            y_proba_pred_corrected = []
            for a_y in y_proba_pred:
                y_proba_pred_corrected.append(y_test_dict[a_y])

            y_prob_acc = np.mean(y_test.ravel() == y_proba_pred_corrected)

            behavior_scores[a_behavior] = y_prob_acc # Save accuracy
            behavior_proba[a_behavior] = y_proba * y_prob_acc # weighted probability
            
            #################################################################
            if print_plots:
                fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10, 5))
                fig.suptitle(a_behavior+', Accuracy: '+str(round(y_prob_acc*100, 1))+'%', fontsize='20')
                
                legend_elements = []
                legend_elements.append(Line2D([0], [0], marker='s', color='w', label='Source (Train)', markerfacecolor='k', markersize=12))
                legend_elements.append(Line2D([0], [0], marker='o', color='w', label='Target (Test: True Labels)', markerfacecolor='k', markersize=12))

                for obj_lab in sorted(test_target_objects):
                    obj_lab += 1
                    obj_name = OBJECT_LABELS_WEIGHTS[new_lables_old_lables[obj_lab]]
                    indices = np.where(Y1_train_test_obj[:, 0] == obj_lab)
                    
                    ax.scatter(Z1_train_test_obj[indices, 0], Z1_train_test_obj[indices, 1],
                               c=np.repeat(MY_COLORS[obj_lab-1], SOURCE_DATA_PERCENT), s=100, edgecolor='red', marker='s')
                    ax.scatter(Z2_train_test_obj[indices, 0], Z2_train_test_obj[indices, 1],
                               c=np.repeat(MY_COLORS[obj_lab-1], SOURCE_DATA_PERCENT), s=100, edgecolor='blue', marker='s')
                    indices = np.where(y_test[:, 0] == obj_lab)
                    ax.scatter(Z3_test[indices, 0], Z3_test[indices, 1],
                               c=np.repeat(MY_COLORS[obj_lab-1], TRIALS_PER_OBJECT), s=100, edgecolor='black', marker='o', label=str(obj_lab)+" ("+str(obj_name)+" kg)")
                
예제 #9
0
    plt.scatter(835 - after_x[i],
                after_y[i],
                c='tab:orange',
                s=50,
                alpha=0.7,
                edgecolors='none')
# Specify Bounds
plt.axis([-50, 350, 200, 800])
# Specify Axis Labels
from matplotlib.patches import Patch
from matplotlib.lines import Line2D

legend_elements = [
    Line2D([0], [0],
           marker='o',
           color='w',
           label='100nM fMLP',
           markerfacecolor='tab:blue',
           markersize=10),
    Line2D([0], [0],
           marker='o',
           color='w',
           label='0nM fMLP',
           markerfacecolor='tab:orange',
           markersize=10),
]

plt.legend(handles=legend_elements, loc='upper right', shadow=False)
plt.xlabel('Position along channel (um)', size=16)
plt.ylabel('Position across channel (um)', size=16)
#plt.title('Scatter plot of cells', size=16)
# Voila
예제 #10
0
def linear_calibration():

    pks_lit = [609.32, 1460.82]

    with open("runDB.json") as f:
        runDB = json.load(f)
    tier_dir = os.path.expandvars(runDB["tier_dir"])
    meta_dir = os.path.expandvars(runDB["meta_dir"])

    df = pd.read_hdf('{}/t2_run{}.h5'.format(tier_dir, sys.argv[1]))

    m = np.array(df['e_ftp'])

    xlo, xhi, xpb = 0, 10000, 10
    nbins = int((xhi - xlo) / xpb)

    hist, bins = np.histogram(m, nbins, (xlo, xhi))
    bins = bins + (bins[1] - bins[0]) / 2
    bins = bins[0:(len(bins) - 1)]
    #hist = np.append(hist, 0)

    hmed = medfilt(hist, 5)
    hpks = hist - hmed

    thresholds = np.arange(50, 750, 10, dtype=int)

    for i in range(len(thresholds)):
        maxes, mins = pgu.peakdet(hpks, thresholds[i], bins)
        if len(maxes) == 4:
            break

    x_maxes = []
    for i in range(len(maxes)):
        x_value = maxes[i][0]
        x_maxes.append(x_value)

    ratios = []
    for i in range(len(maxes)):
        for j in range(len(maxes)):
            ratios.append(x_maxes[i] / x_maxes[j])

    print(x_maxes)

    #another way to do the block above
    #import itertools
    #ratios = []
    #for x_i, x_j in itertools.product(x_maxes, x_maxes):
    #ratios.append(x_i/x_j)

    real_ratio = []
    for i in range(len(ratios)):
        real_ratio.append(pks_lit[1] / pks_lit[0])

    ratios_array = np.array(ratios)
    real_ratio_array = np.array(real_ratio)

    closeness = np.absolute(ratios_array - real_ratio_array)

    relevant_entry = np.where(closeness == np.amin(closeness))[0]
    relevant_entry = int(relevant_entry[len(relevant_entry) - 1])

    adc_2_peak_combinations = []
    for i in range(len(x_maxes)):
        for j in range(len(x_maxes)):
            adc_2_peak_combinations.append([x_maxes[j], x_maxes[i]])

    #ADC Values Corresponding to Energy Peaks 1460.820 keV and 2614.511 keV
    adc_values = adc_2_peak_combinations[relevant_entry]

    #Now we model a linear equation to go from ADC value (e_ftp) to real energy using the points (adc_values[0], 1460.820) and (adc_values[1], 2614.511 keV)
    # E = A(e_ftp) + B
    A = float((pks_lit[1] - pks_lit[0]) / (adc_values[1] - adc_values[0]))
    B = float((pks_lit[1] - adc_values[1] * A))
    A = 0.4074162679425837
    B = 0.23267942583743206
    #Now we will add a column to df that represents the energy measured (rather than only having the adc (e_ftp) value measured as the df currently does)
    print('E = {}(e_ftp) + {}'.format(A, B))
    print(A)
    print(B)

    df["e_cal"] = A * df['e_ftp'] + B

    df.to_hdf('{}/Spectrum_{}.hdf5'.format(meta_dir, sys.argv[1]),
              key='df',
              mode='w')

    pks_lit_all = [
        238.6, 351.9, 511.0, 583.2, 609.3, 911.2, 969, 1120.3, 1460.8, 1764.5,
        2614.5
    ]
    plt.axvline(x=238.6,
                ymin=0,
                ymax=30,
                color='red',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=351.9,
                ymin=0,
                ymax=30,
                color='aqua',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=511.0,
                ymin=0,
                ymax=30,
                color='darkgreen',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=583.2,
                ymin=0,
                ymax=30,
                color='darkorange',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=609.3,
                ymin=0,
                ymax=30,
                color='gray',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=911.2,
                ymin=0,
                ymax=30,
                color='brown',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=969.0,
                ymin=0,
                ymax=30,
                color='saddlebrown',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=1120.3,
                ymin=0,
                ymax=30,
                color='navy',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=1460.8,
                ymin=0,
                ymax=30,
                color='olive',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=1764.5,
                ymin=0,
                ymax=30,
                color='indigo',
                linestyle='--',
                lw=1,
                zorder=1)
    plt.axvline(x=2614.5,
                ymin=0,
                ymax=30,
                color='limegreen',
                linestyle='--',
                lw=1,
                zorder=1)
    n = np.array(df['e_cal'])
    plt.hist(n,
             np.arange(0, 9500, 0.5),
             histtype='step',
             color='black',
             zorder=2,
             label='{} entries'.format(len(n)))
    plt.xlim(0, 4000)
    plt.ylim(0, plt.ylim()[1])
    plt.xlabel('Energy (keV)', ha='right', x=1.0)
    plt.ylabel('Counts', ha='right', y=1.0)
    E_cal = 'calibrated energy spectrum, run ' + str(sys.argv[1])
    E_1 = 'E=238.6 keV (212Pb peak)'
    E_2 = 'E=351.9 keV (214Pb peak)'
    E_3 = 'E=511.0 keV (beta+ peak)'
    E_4 = 'E=583.2 keV (208Tl peak)'
    E_5 = 'E=609.3 keV (214Bi peak)*'
    E_6 = 'E=911.2 keV (228Ac peak)'
    E_7 = 'E=969 keV (228Ac peak)'
    E_8 = 'E=1120.3 keV (214Bi peak)'
    E_9 = 'E=1460.8 keV (40K peak)*'
    E_10 = 'E=1764.5 keV (214Bi peak)'
    E_11 = 'E=2614.5 keV (208Tl peak)'
    colors = [
        'black', 'red', 'aqua', 'darkgreen', 'darkorange', 'gray', 'brown',
        'saddlebrown', 'navy', 'olive', 'indigo', 'limegreen'
    ]
    lines = [Line2D([0], [0], color=c) for c in colors]
    labels = [E_cal, E_1, E_2, E_3, E_4, E_5, E_6, E_7, E_8, E_9, E_10, E_11]
    #plt.title('Energy Spectrum')
    plt.legend(lines,
               labels,
               frameon=True,
               loc='upper right',
               fontsize='x-small')
    plt.tight_layout()
    #plt.semilogy()
    plt.show()
예제 #11
0
def size_lumin_grid_allf(data, intr_data, snaps, filters, orientation, Type,
                         extinction, mtype, weight_norm, xlims, ylims, sample):
    trans = {}
    plt_lams = []
    cents = []
    bounds = []
    lam_max = 0
    i = 1
    for f in filters:
        l, t = np.loadtxt(filter_path + '/' + '/'.join(f.split('.')) + '.txt',
                          skiprows=1).T
        wid = np.max(l[t > 0]) - np.min(l[t > 0])
        trans[f] = []
        trans[f].append(np.min(l[t > 0]))
        trans[f].append(i)
        trans[f].append(np.max(l[t > 0]))
        plt_lams.append(np.max(l[t > 0]) - (wid / 2))
        cents.append(i)
        bounds.append(i - 0.5)
        print(f.split(".")[-1], np.min(l[t > 0]), np.max(l[t > 0]))
        if np.max(l[t > 0]) > lam_max:
            lam_max = np.max(l[t > 0])
        i += 1

    cmap = mpl.cm.get_cmap('viridis', len(filters))

    cmaps = {filters[0]: "Blues", filters[-1]: "Reds"}

    bounds.append(i + 0.5)

    sinds = np.argsort(plt_lams)
    filters = np.array(filters)[sinds]

    filter_labels = [f.split(".")[-1] for f in filters]

    bounds = list(sorted(bounds))

    norm = cm.Normalize(vmin=min(bounds), vmax=max(bounds), clip=True)

    print("Plotting for:")
    print("Orientation =", orientation)
    print("Type =", Type)

    fig = plt.figure(figsize=(18, 6))
    gs = gridspec.GridSpec(2, len(snaps), height_ratios=(5, 2))
    gs.update(wspace=0.0, hspace=0.0)
    axes = []
    axes_ratio = []
    ylims_ratio = []
    i = 0
    while i < len(snaps):
        axes.append(fig.add_subplot(gs[0, i]))
        axes_ratio.append(fig.add_subplot(gs[1, i]))
        axes[-1].loglog()
        axes_ratio[-1].semilogx()
        if i > 0:
            axes[-1].tick_params(axis='y',
                                 left=False,
                                 right=False,
                                 labelleft=False,
                                 labelright=False)
            axes[-1].tick_params(axis='x',
                                 top=False,
                                 bottom=False,
                                 labeltop=False,
                                 labelbottom=False)
            axes_ratio[-1].tick_params(axis='y',
                                       left=False,
                                       right=False,
                                       labelleft=False,
                                       labelright=False)
        i += 1

    legend_elements = []

    for i, snap in enumerate(snaps):

        print("---------------------------", snap,
              "---------------------------")

        z_str = snap.split('z')[1].split('p')
        z = float(z_str[0] + '.' + z_str[1])

        for f in filters:
            print(f)

            compact_ncom = data[snap][f]["Compact_Population_NotComplete"]
            diffuse_ncom = data[snap][f]["Diffuse_Population_NotComplete"]
            compact_com = data[snap][f]["Compact_Population_Complete"]
            diffuse_com = data[snap][f]["Diffuse_Population_Complete"]

            if sample == "Complete":
                complete = np.logical_or(compact_com, diffuse_com)
            else:
                complete = data[snap][f]["okinds"]

            if mtype == "part":
                hlrs = np.array(data[snap][f]["HLR_0.5"])[complete]
                lumins = np.array(data[snap][f]["Image_Luminosity"])[complete]
                intr_hlrs = np.array(intr_data[snap][f]["HLR_0.5"])[complete]
                intr_lumins = np.array(
                    intr_data[snap][f]["Image_Luminosity"])[complete]
            elif mtype == "app":
                hlrs = np.array(data[snap][f]["HLR_Aperture_0.5"])[complete]
                lumins = np.array(data[snap][f]["Image_Luminosity"])[complete]
                intr_hlrs = np.array(
                    intr_data[snap][f]["HLR_Aperture_0.5"])[complete]
                intr_lumins = np.array(
                    intr_data[snap][f]["Image_Luminosity"])[complete]
            else:
                hlrs = np.array(data[snap][f]["HLR_Pixel_0.5"])[complete]
                lumins = np.array(data[snap][f]["Image_Luminosity"])[complete]
                intr_hlrs = np.array(
                    intr_data[snap][f]["HLR_Pixel_0.5"])[complete]
                intr_lumins = np.array(
                    intr_data[snap][f]["Image_Luminosity"])[complete]
            low_lum = data[snap][f]["Complete_Luminosity"]
            w = np.array(data[snap][f]["Weight"])[complete]
            mass = np.array(data[snap][f]["Mass"])[complete]

            try:
                fit_lumins = np.logspace(np.log10(low_lum),
                                         np.log10(np.max(lumins)), 1000)

                popt, pcov = curve_fit(r_fit,
                                       lumins,
                                       hlrs,
                                       p0=(0.5, 0),
                                       sigma=w)

                fit = r_fit(fit_lumins, popt[0], popt[1])
                print(
                    snap, "Total [R_0, Beta]",
                    "[%.3f +/- %.3f & %.3f +/- %.3f], N=%d" %
                    (popt[0], np.sqrt(pcov[0, 0]), popt[1], np.sqrt(
                        pcov[1, 1]), lumins.size))
                axes[i].plot(fit_lumins,
                             fit,
                             linestyle='-',
                             color=cmap(norm(trans[f][1])),
                             alpha=0.9,
                             zorder=2,
                             label=f.split(".")[-1])
                if int(z) in [7, 8]:
                    if f.split(".")[-1] in bt_fits[int(z)].keys():
                        bt_fit_lumins = np.logspace(np.log10(np.min(lumins)),
                                                    np.log10(np.max(lumins)),
                                                    1000)
                        fit = r_fit(fit_lumins,
                                    bt_fits[int(z)][f.split(".")[-1]][1],
                                    bt_fits[int(z)][f.split(".")[-1]][0])
                        print("BT", bt_fits[int(z)][f.split(".")[-1]])
                        axes[i].plot(bt_fit_lumins,
                                     fit,
                                     linestyle='--',
                                     color=cmap(norm(trans[f][1])),
                                     alpha=0.6,
                                     zorder=1)

            except ValueError as e:
                print(e, f, "Total")

            try:
                popt, pcov = curve_fit(st_line_fit,
                                       lumins,
                                       hlrs / intr_hlrs,
                                       p0=(1, 1),
                                       sigma=w)

                print("Ratio", popt)
                fit = st_line_fit(fit_lumins, popt[0], popt[1])

                axes_ratio[i].plot(fit_lumins,
                                   fit,
                                   linestyle='-',
                                   color=cmap(norm(trans[f][1])),
                                   alpha=0.9,
                                   zorder=1,
                                   label=f.split(".")[-1])
            except ValueError as e:
                print(e, f, "Intrinsic")

            # if f == filters[-1]:
            #     print(f, np.log10(np.min(lumins)), np.log10(np.max(lumins)))
            #     axes[i].hexbin(lumins,
            #                    hlrs, gridsize=50,
            #                    mincnt=0.00001,
            #                    C=w,
            #                    reduce_C_function=np.sum,
            #                    xscale='log', yscale='log',
            #                    norm=weight_norm, linewidths=0.2,
            #                    cmap=cmaps[f], alpha=0.5)

        axes[i].text(0.95,
                     0.95,
                     f'$z={z}$',
                     bbox=dict(boxstyle="round,pad=0.3",
                               fc='w',
                               ec="k",
                               lw=1,
                               alpha=0.8),
                     transform=axes[i].transAxes,
                     horizontalalignment='right',
                     fontsize=8)

        axes[i].tick_params(axis='y', which='minor', left=True)
        axes_ratio[i].tick_params(axis='both',
                                  which='minor',
                                  bottom=True,
                                  left=True)

        ylims_ratio.append(axes_ratio[i].get_ylim())

        this_xlims = axes[i].get_xlim()
        if this_xlims[0] < xlims[0]:
            xlims[0] = this_xlims[0]
        if this_xlims[1] > xlims[1]:
            xlims[1] = this_xlims[1]

        # Label axes
        axes_ratio[i].set_xlabel(r"$L/$ [erg $/$ s $/$ Hz]")

    for i, snap in enumerate(snaps):

        axes[i].set_xlim(xlims[0], xlims[1])
        axes_ratio[i].set_xlim(xlims[0], xlims[1])
        axes_ratio[i].tick_params(axis='x', which='both', bottom=True)

    for i in range(len(axes)):
        axes[i].set_ylim(ylims[0], ylims[1])
        axes_ratio[i].set_ylim(np.min(ylims_ratio), np.max(ylims_ratio))

    axes[0].set_ylabel('$R_{1/2}/ [pkpc]$')
    axes_ratio[0].set_ylabel('$R_{1/2, Att}/ R_{1/2, Int}$')
    axes[0].tick_params(axis='y', which='both', left=True)
    axes_ratio[0].tick_params(axis='y', which='both', left=True)

    uni_legend_elements = []
    uni_legend_elements.append(
        Line2D([0], [0], color="k", linestyle="-", label="FLARES"))
    uni_legend_elements.append(
        Line2D([0], [0], color="k", linestyle="--", label="BlueTides"))
    for f in filters:
        uni_legend_elements.append(
            Line2D([0], [0],
                   color=cmap(norm(trans[f][1])),
                   linestyle="-",
                   label=f.split(".")[-1]))
    included = []
    for l in legend_elements:
        if (l.get_label(), l.get_marker()) not in included:
            print((l.get_label(), l.get_marker()))
            uni_legend_elements.append(l)
            included.append((l.get_label(), l.get_marker()))

    axes_ratio[2].legend(handles=uni_legend_elements,
                         loc='upper center',
                         bbox_to_anchor=(0.5, -0.35),
                         fancybox=True,
                         ncol=len(uni_legend_elements))

    fig.savefig('plots/FilterCompHalfLightRadius_' + mtype + "_" + sample +
                '_' + orientation + '_' + Type + "_" + extinction + ".png",
                bbox_inches='tight',
                dpi=300)

    plt.close(fig)
예제 #12
0
    def init_figure(self):
        ''' initial drawing '''

        limit = [
            30.3, 0
        ]  # there is a case of tscl.tsfpos=24.28, so limit is at least 24.28 + 6 = 30.28
        front_init = 16
        self.rear1_pos = rear1_init = 4
        rear2_init = 10

        # top screen front/rear length/width
        self.screen_len = 6  # 6 meter
        screen_width = 0.2

        self.screen_color = 'green'
        self.normal_color = 'black'
        self.alarm_color = 'red'

        # front/rear top screen
        ts_kwargs=dict(alpha=0.8, fc=self.screen_color, \
                       ec=self.screen_color, lw=1, )
        self.front=mpatches.Rectangle((front_init, screen_width - screen_width), \
                                      self.screen_len, screen_width, **ts_kwargs)

        self.rear1=mpatches.Rectangle((rear1_init, screen_width*2), \
                                      self.screen_len, screen_width, \
                                      **ts_kwargs)
        self.rear2=mpatches.Rectangle((rear2_init, screen_width), \
                                      self.screen_len, screen_width, \
                                      **ts_kwargs)

        self.axes.add_patch(self.front)
        self.axes.add_patch(self.rear1)
        self.axes.add_patch(self.rear2)

        # draw x-axis line
        line_kwargs = dict(alpha=0.7,
                           ls='-',
                           lw=0.7,
                           color=self.screen_color,
                           marker='.',
                           ms=10.0,
                           mew=1,
                           markevery=(0, 1))

        middle = [max(limit), min(limit)]
        line = Line2D(middle, [self.center_y] * len(middle), **line_kwargs)
        self.axes.add_line(line)

        # draw text
        self.text=self.axes.text(0.5, 0.2, 'Initializing', \
                                 va='baseline', ha='center', \
                                 transform = self.axes.transAxes, \
                                             color=self.normal_color, \
                                             fontsize=13)

        # set x,y limit values
        self.axes.set_xlim(max(limit), min(limit))
        self.axes.set_ylim(min(self.y_axis), max(self.y_axis))
        # # disable default x/y axis drawing
        #self.axes.set_xlabel(False)
        #self.axes.apply_aspect()
        self.axes.set_axis_off()

        #self.axes.set_xscale(10)
        self.axes.axison = False
        self.draw()
예제 #13
0
    ax1.tick_params('y', colors='r')
    if mintemp < minextemp: bot = mintemp
    else: bot = minextemp
    if maxtemp > maxextemp: tp = maxtemp
    else: tp = maxextemp
    ax1.set_ylim(bottom=bot, top=tp)
    if args.date is not None:
        title = "Conditions du poulailler le " + args.date + "-" + str(
            curtime.tm_year)
    else:
        title = "Conditions du poulailler le {}/{}/{}".format(
            curtime.tm_mday, curtime.tm_mon, curtime.tm_year)
    ax1.set_title("Conditions du poulailler le {}/{}/{}".format(
        curtime.tm_mday, curtime.tm_mon, curtime.tm_year))
    hightemp = Line2D([mint, maxt], [35, 35],
                      linewidth=0.5,
                      linestyle='--',
                      color='xkcd:brick red')
    ax1.add_line(hightemp)
    if maxtemp > 35:
        ax1.text(0, 35.5, "T° max reco.", fontsize=7, color='xkcd:dark red')
    if maxt >= 12:
        ax1.xaxis.set_ticks(np.arange(0, maxt, step=round(maxt / 12)))
    else:
        import math
        ax1.xaxis.set_ticks(np.arange(0, maxt, step=math.ceil(maxt / 12)))

    # Humidities
    ax2 = ax1.twinx()
    axhum = ax2.plot(values['time'],
                     values['hum'],
                     'b-',
예제 #14
0
 tendonForce = np.array(
     list(
         map(lambda x: plant.tendon_1_FL_func([0, 0, x, 0, 0, 0]),
             scaledTendonDeformation))
 )  # NOTE: by setting x1 = 0 and x3 as the scaled tendon deformation, we create a new function that is a function of tendon deformation only.
 UBidx = int(sum(tendonForce <= 400))
 label = (
     r"$k_{sp}$ = " + '{:0.2f}'.format(
         tendonStiffnessParams["Spring Stiffness Coefficient"]) + "\n" +
     r"$b_{sp}$ = " +
     '{:0.2f}'.format(tendonStiffnessParams["Spring Shape Coefficient"]))
 labels.append(
     Line2D([0], [0],
            color="C0",
            label=label,
            lw=0,
            marker='|',
            linestyle=None,
            markersize=40,
            markeredgewidth=15))
 line, = ax.plot(tendonDeformation * 100, tendonForce, c="C0", label=label)
 lines.append(line)
 ax.legend(handles=labels,
           bbox_to_anchor=(0, -0.35, 1, .162),
           ncol=3,
           mode="expand",
           loc=3,
           borderaxespad=3,
           fontsize=14)
 # ax.legend(["this is a \n test","test","test 2"],loc="upper left")
 ax.spines["top"].set_visible(False)
 ax.spines["right"].set_visible(False)
예제 #15
0
def bistability_in_parameter_space_figure():

    # Ticks in integer format instead of float
    def my_formatter(x, pos):
        val_str = '{:g}'.format(x)
        if val_str == '0.0':
            val_str = '0'
        return val_str

    from matplotlib.ticker import FuncFormatter
    major_formatter = FuncFormatter(my_formatter)

    # Set font sizes
    font = {'family': 'Arial', 'size': 10}

    rc('font', **font)
    rc('xtick', labelsize=8)
    rc('ytick', labelsize=8)

    # Define grids for figures (gs upper grid for MDS and 2DS, gs2 for lower grid for 3DS)
    wspace = 0.05
    hspace = 0.05
    gs = gridspec.GridSpec(
        13,
        11,
        height_ratios=[1, 1, 1, 1, 1, 1.5, 1, 1, 1, 1, 1, 1, 1],
        width_ratios=[1, 1, 1, 1, 1, 1.3, 1, 1, 1, 1, 1],
        wspace=wspace,
        hspace=hspace)
    gs2 = gridspec.GridSpec(
        13,
        9,
        height_ratios=[1, 1, 1, 1, 1, 1.5, 1, 1, 1, 1, 1, 1, 1],
        width_ratios=[1, 1, 1, 1, 1, 1, 1, 0.3, 3],
        wspace=wspace,
        hspace=hspace)

    # Label parameters (font size and distances)
    width_distance_label_subfigure = -0.05
    height_distance_label_subfigure = 1.5
    coordinate_y_labels = -0.6
    label_size = 8

    # Make figure
    fig = plt.figure(figsize=(6, 8))

    # Function that returns set of axes
    def make_axes(labels, gs, ox=0, oy=0):
        ax = [[0 for _ in range(len(labels))] for _ in range(len(labels))]
        diag_ax = [0 for _ in range(len(labels))]

        for i in range(len(labels)):
            for j in range(len(labels)):
                if i == 0 and j == 0:
                    ax[i][j] = fig.add_subplot(gs[i + oy, j + ox])
                    diag_ax[i] = ax[i][j]._make_twin_axes(sharex=ax[i][j],
                                                          frameon=False)
                    diag_ax[i].axis('off')
                elif j == 0:
                    ax[i][j] = fig.add_subplot(gs[i + oy, j + ox],
                                               sharex=ax[0][0])
                elif i == 0:
                    ax[i][j] = fig.add_subplot(gs[i + oy, j + ox],
                                               sharey=ax[0][0])
                elif i == j:
                    ax[i][j] = fig.add_subplot(gs[i + oy, j + ox],
                                               sharey=diag_ax[0],
                                               sharex=ax[0][j])
                    diag_ax[i] = ax[i][j]._make_twin_axes(sharex=ax[i][j],
                                                          sharey=diag_ax[0],
                                                          frameon=False)
                    diag_ax[i].axis('off')
                else:
                    ax[i][j] = fig.add_subplot(gs[i + oy, j + ox],
                                               sharex=ax[0][j],
                                               sharey=ax[i][0])

                ax[i][j].tick_params(axis='both', which='major', length=3)
                if i != len(labels) - 1:
                    plt.setp(ax[i][j].get_xticklabels(), visible=False)
                    ax[i][j].tick_params(axis='x',
                                         which='major',
                                         labelsize=label_size,
                                         length=3)
                if j != 0:
                    plt.setp(ax[i][j].get_yticklabels(), visible=False)
                    ax[i][j].tick_params(axis='y',
                                         which='major',
                                         labelsize=label_size,
                                         length=3)

        for i in range(len(labels)):
            ax[-1][i].set_xlabel(labels[i])
            ax[i][0].set_ylabel(labels[i])
            ax[i][0].get_yaxis().set_label_coords(coordinate_y_labels, 0.5)
            ax[i][0].yaxis.set_major_formatter(major_formatter)
            ax[-1][i].xaxis.set_major_formatter(major_formatter)

        return ax, diag_ax

    # Function that fills the axes with the data
    def fill_axes_data(data, ax, diag_ax, parname, parameter_ranges):
        for i in range(len(parname)):
            for j in range(len(parname)):
                if i == j:
                    vals = []
                    for k in range(4):
                        # Attempt to get data for this level, allowing for empty
                        try:
                            vals.append(
                                np.log10(
                                    data[parname[i]][data['nonmono'] == k]))
                        except KeyError:
                            vals.append(np.array([]))

                    diag_ax[i].hist(vals,
                                    color=colorp,
                                    histtype="barstacked",
                                    bins=7,
                                    range=parameter_ranges[i])
                elif i > j:
                    ax[i][j].scatter(
                        np.log10(data[parname[j]][data['nonmono'] == 1]),
                        np.log10(data[parname[i]][data['nonmono'] == 1]),
                        c=colorp[1],
                        s=1)
                    ax[i][j].scatter(
                        np.log10(data[parname[j]][data['nonmono'] == 2]),
                        np.log10(data[parname[i]][data['nonmono'] == 2]),
                        c=colorp[2],
                        s=1)
                    ax[i][j].scatter(
                        np.log10(data[parname[j]][data['nonmono'] == 3]),
                        np.log10(data[parname[i]][data['nonmono'] == 3]),
                        c=colorp[3],
                        s=1)
                else:
                    ax[i][j].scatter(
                        np.log10(data[parname[j]][data['nonmono'] == 0]),
                        np.log10(data[parname[i]][data['nonmono'] == 0]),
                        c=colorp[0],
                        s=1)

    # Plot different subfigures

    plotMDS = True
    plot2DS = True
    plot3DS = True

    if plotMDS:
        # Read data
        f = 'bistability/MDS/H500-600.csv'

        data = pd.read_csv(f, na_values='NAN')

        # Define parameters, and ranges
        parname = ['Kd', 'Km', 'fd', 'fm', 'T']
        labels = [
            r'$K_d^*$', r'$K_m^*$', '$f_d^*$', '$f_m^*$', r'$\Delta t^*$'
        ]

        parameter_ranges = [(-7, 3), (-10, 3), (-3, 2), (-3, 2), (3, 4)]

        # Make the axes, write the label and plot the data
        ax, diag_ax = make_axes(labels, gs)

        ax[0][0].text(width_distance_label_subfigure,
                      height_distance_label_subfigure,
                      'A. MDS',
                      transform=ax[0][0].transAxes,
                      va='top',
                      ha='right')

        fill_axes_data(data, ax, diag_ax, parname, parameter_ranges)

        # Contour the physiological parameter space
        for i in range(len(labels)):
            for j in range(i + 1, len(labels)):
                if not (i == len(labels) - 1 or j == len(labels) - 1):
                    ax[i][j].plot([
                        parameter_ranges[j][0], parameter_ranges[j][0],
                        parameter_ranges[j][1], parameter_ranges[j][1],
                        parameter_ranges[j][0]
                    ], [
                        parameter_ranges[i][1], parameter_ranges[i][0],
                        parameter_ranges[i][0], parameter_ranges[i][1],
                        parameter_ranges[i][1]
                    ],
                                  'k:',
                                  linewidth=0.5)
                    ax[j][i].plot([
                        parameter_ranges[i][0], parameter_ranges[i][0],
                        parameter_ranges[i][1], parameter_ranges[i][1],
                        parameter_ranges[i][0]
                    ], [
                        parameter_ranges[j][1], parameter_ranges[j][0],
                        parameter_ranges[j][0], parameter_ranges[j][1],
                        parameter_ranges[j][1]
                    ],
                                  'k:',
                                  linewidth=0.5)

    if plot2DS:
        # Read data
        f = 'bistability/2DS/H500-600.csv'

        data = pd.read_csv(f, na_values='NAN')

        # Define parameters, and ranges
        parname = ['A', 'B', 'C', 'D', 'T']
        labels = [r'$A^*$', r'$B^*$', '$C^*$', '$D^*$', r'$\Delta t^*$']
        parameter_ranges = [(-15, 7), (-8, 8), (-12, 5), (-5, 5), (2.7, 4)]

        # Make the axes, write the label and plot the data
        ax, diag_ax = make_axes(labels, gs, ox=6)
        ax[0][0].text(width_distance_label_subfigure,
                      height_distance_label_subfigure,
                      'B. 2DS',
                      transform=ax[0][0].transAxes,
                      va='top',
                      ha='right')

        fill_axes_data(data, ax, diag_ax, parname, parameter_ranges)

        # Contour the physiological parameter space
        for i in range(len(labels)):
            for j in range(i + 1, len(labels)):
                if not (i == len(labels) - 1 or j == len(labels) - 1):
                    p = np.hstack((np.array([np.log10(data[parname[j]])]).T,
                                   np.array([np.log10(data[parname[i]])]).T))
                    hull = ConvexHull(p)
                    for simplex in hull.simplices:
                        print(simplex)
                        ax[i][j].plot(p[simplex, 0],
                                      p[simplex, 1],
                                      'k:',
                                      linewidth=0.5)
                        ax[j][i].plot(p[simplex, 1],
                                      p[simplex, 0],
                                      'k:',
                                      linewidth=0.5)

    if plot3DS:
        # Read data
        f = 'bistability/3DS/H500-600.csv'

        data = pd.read_csv(f, na_values='NAN')
        data = data[np.logical_and(
            np.logical_and(data['nonmono'] < 4, data['T'] >= -1),
            ~np.isnan(data['T']))]

        # Define parameters, and ranges
        parname = ['A', 'B', 'C', 'D', 'E', 'F', 'T']
        labels = [
            r'$A^*$', r'$B^*$', '$C^*$', '$D^*$', '$E^*$', '$F^*$',
            r'$\Delta t^*$'
        ]
        parameter_ranges = [(-29.9, 29.9), (-14.9, 14.9), (-8, 8),
                            (-24.9, 24.9), (-14.9, 14.9), (-4.5, 4.5),
                            (2.55, 3.9)]

        # Make the axes, write the label and plot the data
        ax, diag_ax = make_axes(labels, gs2, oy=6)
        ax[0][0].text(width_distance_label_subfigure,
                      height_distance_label_subfigure,
                      'C. 3DS',
                      transform=ax[0][0].transAxes,
                      va='top',
                      ha='right')
        fill_axes_data(data, ax, diag_ax, parname, parameter_ranges)

        # Contour the physiological parameter space
        for i in range(len(labels)):
            for j in range(i + 1, len(labels)):
                if not (i == len(labels) - 1 or j == len(labels) - 1):
                    x1, y1, x2, y2 = min_max_values_3DS_physiological_range(
                        parname[j], parname[i])
                    ax[i][j].plot(np.log10(x1),
                                  np.log10(y1),
                                  'k:',
                                  linewidth=0.5)
                    ax[i][j].plot(np.log10(x2),
                                  np.log10(y2),
                                  'k:',
                                  linewidth=0.5)
                    if len(x1) > 0:
                        ax[i][j].plot(
                            [np.log10(x1[0]), np.log10(x2[0])],
                            [np.log10(y1[0]), np.log10(y2[0])],
                            'k:',
                            linewidth=0.5)
                        ax[i][j].plot([np.log10(x1[-1]),
                                       np.log10(x2[-1])],
                                      [np.log10(y1[-1]),
                                       np.log10(y2[-1])],
                                      'k:',
                                      linewidth=0.5)

                    ax[j][i].plot(np.log10(y1),
                                  np.log10(x1),
                                  'k:',
                                  linewidth=0.5)
                    ax[j][i].plot(np.log10(y2),
                                  np.log10(x2),
                                  'k:',
                                  linewidth=0.5)
                    if len(x1) > 0:
                        ax[j][i].plot(
                            [np.log10(y1[0]), np.log10(y2[0])],
                            [np.log10(x1[0]), np.log10(x2[0])],
                            'k:',
                            linewidth=0.5)
                        ax[j][i].plot([np.log10(y1[-1]),
                                       np.log10(y2[-1])],
                                      [np.log10(x1[-1]),
                                       np.log10(x2[-1])],
                                      'k:',
                                      linewidth=0.5)

    # Plot legend.
    axleg = fig.add_subplot(gs2[6:, 7:], frameon=False)

    legend_elements = [
        Line2D([0], [0],
               color='w',
               lw=2,
               label='monotonic',
               marker='o',
               markerfacecolor=colorp[0],
               markersize=3),
        Line2D([0], [0],
               color='w',
               lw=2,
               label='non-monotonic 1',
               marker='o',
               markerfacecolor=colorp[1],
               markersize=3),
        Line2D([0], [0],
               color='w',
               lw=2,
               label='non-monotonic 2',
               marker='o',
               markerfacecolor=colorp[2],
               markersize=3),
        Line2D([0], [0],
               color='w',
               lw=2,
               label='non-monotonic 3',
               marker='o',
               markerfacecolor=colorp[3],
               markersize=3)
    ]

    axleg.legend(handles=legend_elements,
                 loc='center',
                 fontsize=10,
                 handlelength=0.5,
                 ncol=1,
                 frameon=False)
    axleg.axis('off')

    # Save and show figure
    #gs.tight_layout(fig)

    #fig.savefig('Figures/bistabpars.png')
    plt.show()
예제 #16
0
def plot_quantiles_cost_n_miss(
        root_exp_folder,
        subfolds=("uniform", "prediction", "stratum"),
        sf_style={
            "uniform": {
                "color": "blue",
                "label": "Uniform"
            },
            "prediction": {
                "color": "green",
                "label": "Weighted"
            },
            "stratum": {
                "color": "green",
                "label": "Stratum"
            },
        },
        alpha=0.05,
        figsize=(3, 3),
        lim_acc=None,
        lim_cost=None,
        lim_top=None,
        camera_ready=True):
    """
        Plot the quantile graphs for a standardized experiment.

        If the experiment data is in a folder named exp, it expects to find
        subfolders subfolds in which there are folders with runs and a
        params.json file that contains the result of the runs. It will generate
        a quantile plot for each of the experiments.
    """
    print("Loading the data...")
    list_params_list = list()
    for type_weight in subfolds:
        list_params_list.append(
            get_param_list_for_quantiles(root_exp_folder, type_weight))

    print("Plotting results...")
    for plotted_val in ("acc", "cost", "topk"):
        plt.figure(figsize=figsize)
        for itw, type_weight in enumerate(subfolds):
            params_list = list_params_list[itw]

            params = params_list[0]

            color = sf_style[type_weight]["color"]

            plot_quant(params_list,
                       "{}_test".format(plotted_val),
                       "",
                       color=color)
            plt.plot(params["step"],
                     param_list_to_quant("{}_train".format(plotted_val), 0.5,
                                         params_list),
                     color=color,
                     linestyle="--")
        if plotted_val == "acc" and lim_acc:
            plt.ylim(lim_acc)
            plt.ylabel("Miss rate")
        if plotted_val == "cost" and lim_cost:
            plt.ylim(lim_cost)
            plt.ylabel("SCE")
        if plotted_val == "topk" and lim_top:
            plt.ylim(lim_top)
            plt.ylabel("Top-5 error")
        if not camera_ready:
            plt.title(plotted_val)

        train_lgd = Line2D([0, 0], [1, 1], color="black", linestyle="--")
        test_lgd = Line2D([0, 0], [1, 1], color="black", linestyle="-")
        legend1 = plt.gca().legend([train_lgd, test_lgd], ["Train", "Test"],
                                   loc="upper right")
        legend_lines = [
            Line2D([0, 0], [1, 1], color=sf_style[k]["color"], linestyle="-")
            for k in subfolds
        ]
        legend_names = [sf_style[k]["label"] for k in subfolds]
        plt.gca().legend(legend_lines, legend_names, loc="lower left")
        plt.gca().add_artist(legend1)

        plt.grid()
        plt.tight_layout()
        # elif plotted_val == "acc":
        #     plt.title("Miss rate")
        # else:
        #     plt.title("SCE")
        plt.savefig("{}/{}_{}.pdf".format(root_exp_folder, "quant",
                                          plotted_val),
                    format="pdf")
    print("Done !")
예제 #17
0
            xy=(np.sin(np.deg2rad(14.5)), 0.8 * -170),
            xycoords="data",
            xytext=(-45, 0.8 * -1.8),
            textcoords="offset points",
            arrowprops=dict(arrowstyle="->", connectionstyle="arc3"))
ax.set_xticks(np.sin(np.deg2rad(np.arange(-90, 91, 10))))
ax.set_xticklabels([
    "90°S", "", "", "", "", "", "30°S", "", "", "EQ", "", "", "30°N", "", "",
    "", "", "", "90°N"
])
ax.set_ylim([0.8 * -200, 0.8 * 20])
ax.set_xlabel("Latitude")
ax.set_ylabel("Forcing, $S'(1 - \\alpha)$ (W m$^{-2}$)")

legend_elements = [
    Line2D([0], [0], color="r", linestyle="-", alpha=0.5, label="Tropical"),
    Line2D([0], [0],
           color="b",
           linestyle="--",
           alpha=0.5,
           label="Extratropical")
]
ax.legend(handles=legend_elements, loc="lower left")

ax = axes[1]

T_min = 205
T_max = 301

directory = "/home/hpeter/Documents/ResearchBoos/EBM_files/EBM_sims/sim292"
for i, M in enumerate([5, 10, 15, 18]):
예제 #18
0
    ax2.set_xticks(range(-90, 91, 30))
    ax2.set_xticks(range(-90, 91, 10), minor=True)
    ax2.set_yticks(np.arange(0.0, 0.21, 0.05))
    ax2.set_yticks(np.arange(0.0, 0.21, 0.01), minor=True)
    ax2.grid(alpha=0.2)
    ax3.set_xticks(range(-90, 91, 30))
    ax3.set_xticks(range(-90, 91, 10), minor=True)
    ax3.set_yticks(np.arange(0.0, 0.21, 0.05))
    ax3.set_yticks(np.arange(0.0, 0.21, 0.01), minor=True)
    ax3.grid(alpha=0.2)
    ax4.set_xticks(range(-90, 91, 30))
    ax4.set_xticks(range(-90, 91, 10), minor=True)
    ax4.set_yticks(np.arange(0.0, 0.21, 0.05))
    ax4.set_yticks(np.arange(0.0, 0.21, 0.01), minor=True)
    ax4.grid(alpha=0.2)

    handles = [Line2D([0], [0], color=colors[j]) for j in range(nshell)]
    labels = [
        f"{o['name'].split(' ')[0]} ({o['number_of_planes'] * o['satellites_per_plane']} @ {o['altitude_km']:g} km / ${o['inclination_deg']:g}^\circ$)"
        for o in orbital_shells
    ]

    fig.legend(handles,
               labels,
               ncol=3,
               loc="lower center",
               borderaxespad=0.1,
               bbox_to_anchor=(0.5, 1))
    plt.tight_layout()
    plt.savefig("density_with_latitude.png", bbox_inches="tight")
예제 #19
0
파일: reactor.py 프로젝트: StefanPW/Reactor
    def __preparePlot__(self):
        """Creates plot and sets all values"""
        #PLOT
        self.fig, self.ax1 = plt.subplots()
        self.ax2 = self.ax1.twinx()

        self.startPoint = self.nt
        self.x = []
        self.lineTf = Line2D(self.x,
                             self.listTf,
                             color='g',
                             animated=True,
                             markersize=1,
                             linewidth=2,
                             label="Tf")
        self.lineTc = Line2D(self.x,
                             self.listTc,
                             color='b',
                             animated=True,
                             label="Tc")
        self.lineR = Line2D(self.x,
                            self.listR,
                            color='m',
                            animated=True,
                            label="R")
        self.lineDT = Line2D(self.x,
                             self.listDT,
                             color='y',
                             animated=True,
                             label="DT")
        self.lineN = Line2D(self.x,
                            self.listN,
                            color='r',
                            animated=True,
                            markersize=1,
                            linewidth=2,
                            label="Neutron number")
        self.ax1.add_line(self.lineTf)
        self.ax1.add_line(self.lineTc)
        self.ax1.add_line(self.lineR)
        self.ax1.add_line(self.lineDT)
        self.ax2.add_line(self.lineN)
        style.use('fivethirtyeight')
        self.ax1.set_xlabel('time [s]', fontsize=16)
        self.ax2.set_ylabel('N', fontsize=16)
        self.ax1.set_ylabel('Temperatures [deg. C], reactivity [pcm]',
                            fontsize=16)
        self.ax1.set_xlim(xmin=-1)
        self.ax1.set_ylim(ymin=-10, ymax=1200)
        self.ax2.set_ylim(ymin=0, ymax=10E18)
        ###LEGEND
        legend2 = plt.legend(handles=[self.lineN],
                             bbox_to_anchor=(0.2, 0., 1., 1),
                             loc=9,
                             fontsize='small',
                             ncol=1,
                             borderaxespad=0.)
        ax = plt.gca().add_artist(legend2)
        plt.legend(handles=[self.lineTf, self.lineTc, self.lineR, self.lineDT],
                   bbox_to_anchor=(1.05, 0., 1., 1),
                   loc=1,
                   fontsize='small',
                   ncol=1,
                   mode="expand",
                   borderaxespad=0.)
        plt.subplots_adjust(left=0.11,
                            bottom=0.11,
                            right=0.75,
                            top=0.88,
                            wspace=0.2,
                            hspace=0.2)
예제 #20
0
            if samp_idx == 0:
                figure = corner.corner(bilby_pred,
                                       **defaults_kwargs,
                                       labels=parnames,
                                       color=color_cycle[samp_idx],
                                       truths=truths)
            else:
                figure = corner.corner(bilby_pred,
                                       **defaults_kwargs,
                                       labels=parnames,
                                       color=color_cycle[samp_idx],
                                       truths=truths,
                                       fig=figure)
            custom_lines.append(
                Line2D([0], [0], color=legend_color_cycle[samp_idx], lw=4))

        # plot predicted ML results
        corner.corner(VI_pred,
                      **defaults_kwargs,
                      labels=parnames,
                      color='tab:red',
                      fill_contours=True,
                      fig=figure)
        custom_lines.append(Line2D([0], [0], color='red', lw=4))

        if params['Make_sky_plot'] == True:
            # Compute skyplot
            left, bottom, width, height = [0.55, 0.47, 0.5, 0.39]
            ax_sky = figure.add_axes([left, bottom, width, height])
예제 #21
0
    def __init__(self, master):
        self.root = master
        self.root.protocol('WM_DELETE_WINDOW', self.on_closing)
        self.top = self.root.winfo_toplevel()
        self.top.rowconfigure(0, weight=1)
        self.top.columnconfigure(0, weight=1)
        self.fig, self.ax = plt.subplots(4, 1, sharex='col')
        plt.subplots_adjust(hspace=0.35)

        ttk.Style().configure('TButton', foreground='blue')

        btn = ttk.Button(self.root, text='Open...', command=self.OpenConfig)
        btn.grid(row=0, column=0, sticky=tk.NSEW)
        btn = ttk.Button(self.root, text='Start All', command=self.launch_all)
        btn.grid(row=0, column=1, sticky=tk.NSEW)
        btn = ttk.Button(self.root, text='Kill All', command=self.kill_all)
        btn.grid(row=0, column=2, sticky=tk.NSEW)
        btn = ttk.Button(self.root, text='Quit', command=self.Quit)
        btn.grid(row=0, column=3, sticky=tk.NSEW)
        self.labelvar = tk.StringVar()
        self.labelvar.set('Case')
        lab = ttk.Label(self.root, textvariable=self.labelvar, relief=tk.RIDGE)
        lab.grid(row=0, column=4, sticky=tk.NSEW)

        self.root.rowconfigure(0, weight=0)
        self.root.rowconfigure(1, weight=1)
        self.root.columnconfigure(0, weight=0)
        self.root.columnconfigure(1, weight=0)
        self.root.columnconfigure(2, weight=0)
        self.root.columnconfigure(3, weight=0)
        self.root.columnconfigure(4, weight=1)

        self.hrs = [0.0]
        self.y0 = [1.0]
        self.y1 = [0.0]
        self.y2 = [0.0]
        self.y3 = [0.0]
        self.y0min = 1.0
        self.y0max = 1.0
        self.y1min = 0.0
        self.y1max = 0.0
        self.y2min = 0.0
        self.y2max = 0.0
        self.y3min = 0.0
        self.y3max = 0.0
        self.hour_stop = 4.0

        self.ln0 = Line2D(self.hrs, self.y0, color='green')
        self.ln1 = Line2D(self.hrs, self.y1, color='red')
        self.ln2 = Line2D(self.hrs, self.y2, color='blue')
        self.ln3 = Line2D(self.hrs, self.y3, color='magenta')

        self.ax[0].add_line(self.ln0)
        self.ax[0].set_ylabel('[pu]')
        self.ax[0].set_title('PYPOWER Bus Voltage', fontsize=10)

        self.ax[1].add_line(self.ln1)
        self.ax[1].set_ylabel('[kW]')
        self.ax[1].set_title('Primary School Load', fontsize=10)

        self.ax[2].add_line(self.ln2)
        self.ax[2].set_ylabel('[$]')
        self.ax[2].set_title('Clearing Price and LMP', fontsize=10)

        self.ax[3].add_line(self.ln3)
        self.ax[3].set_ylabel('[kW]')
        self.ax[3].set_title('Total Feeder Load', fontsize=10)

        self.ax[3].set_xlabel('Hours')

        self.canvas = FigureCanvasTkAgg(self.fig, self.root)
        self.canvas.draw()
        self.canvas.get_tk_widget().grid(row=1,
                                         columnspan=5,
                                         sticky=tk.W + tk.E + tk.N + tk.S)

        self.bFNCSactive = False
예제 #22
0
파일: view.py 프로젝트: reddqian/NeuroM
 def neurite_legend(neurite_type):
     return Line2D([0], [0], color=TREE_COLOR[neurite_type], lw=2, label=neurite_type.name)
예제 #23
0
        'TP': 'royalblue',
        'TN': 'paleturquoise',
        'FP': 'peachpuff',
        'FN': 'indianred'
    }
    col_vec = [assessment_cols_map[assess] for assess in assessment]

    pts_dict = {'x': pts[:, 0], 'y': pts[:, 1], 'scores': scores}
    pts_df = pd.DataFrame(pts_dict)
    pts_df = pts_df.dropna()

    im0 = ax[0].scatter(pts_df.x, pts_df.y, c=col_vec, edgecolors='black')

    line1 = Line2D(range(1),
                   range(1),
                   color="white",
                   marker='o',
                   markerfacecolor=assessment_cols_map['TP'],
                   markeredgecolor='black')
    line2 = Line2D(range(1),
                   range(1),
                   color="white",
                   marker='o',
                   markerfacecolor=assessment_cols_map['TN'],
                   markeredgecolor='black')
    line3 = Line2D(range(1),
                   range(1),
                   color="white",
                   marker='o',
                   markerfacecolor=assessment_cols_map['FP'],
                   markeredgecolor='black')
    line4 = Line2D(range(1),
예제 #24
0
 def redraw(self):
     variables = []
     if self.includeallcheckBox.isChecked():
         for i in range(self.interactionlistWidget.count()):
             variables.append(self.interactionlistWidget.item(i).text())
     else:
         for i in range(self.selectedlistWidget.count()):
             variables.append(self.selectedlistWidget.item(i).text())
     nX = len(variables)
     if nX < 1:
         QtWidgets.QMessageBox.critical(self,'Error',"Too few variables selected!",\
                                        QtWidgets.QMessageBox.Ok)
         return ()
     Yname = self.YcomboBox.currentText()
     Lc = DS.Lc[DS.Ic]
     Gc = DS.Gc[DS.Ic]
     Lcy = Lc[Gc]
     Lcx = Lc[-Gc]
     data = DS.Raw.loc[DS.Ir, DS.Ic]
     Y = data[Lcy]
     X = data[Lcx]
     if nX > X.shape[0]:
         QtWidgets.QMessageBox.critical(self,'Error',"Factors > Observation! \n Reduce factors.",\
                                        QtWidgets.QMessageBox.Ok)
         return ()
     ny = self.YcomboBox.currentIndex()
     Y = Y.values.astype('float')
     X = X.values.astype('float')
     Y = Y[:, ny]
     nr = len(Y)
     basey = [Term([LookupFactor(Yname)])]
     basex = []
     for term in variables:
         if term == 'Intercept':
             basex = [INTERCEPT]
             variables.remove(term)
     for term in variables:
         vterm = term.split(':')
         term_lookup = [LookupFactor(x) for x in vterm]
         if len(term_lookup) > 1:
             if vterm[0] == vterm[1]:
                 term_lookup = [EvalFactor(vterm[0] + ' ** 2')]
         basex.append(Term(term_lookup))
     desc = ModelDesc(basey, basex)
     data = np.column_stack((X, Y))
     columns = Lcx.tolist()
     columns.append(Yname)
     data = pd.DataFrame(data, columns=columns)
     y, mx = dmatrices(desc, data, return_type='dataframe')
     dism = np.linalg.inv(np.dot(mx.T.values, mx.values))
     mod = OLS(y, mx)
     DOE.res = mod.fit()
     # calculation of cross-validation
     ypcv = list()
     rcv = list()
     bres = list()
     loo = LeaveOneOut()
     loo.get_n_splits(mx)
     for train_index, test_index in loo.split(mx):
         mx_train = mx.ix[train_index, :]
         mx_test = mx.ix[test_index, :]
         y_train = y.ix[train_index, :]
         y_test = y.ix[test_index, :]
         modcv = OLS(y_train, mx_train)
         rescv = modcv.fit()
         ypcv.append(rescv.predict(mx_test).values[0])
         rcv.append(rescv.predict(mx_test).values[0] - y_test.values[0])
         bres.append((rescv.params - DOE.res.params).values**2)
     bres = pd.DataFrame(bres)
     bres = bres.sum() * nr / (nr - 1)
     bres = np.sqrt(bres.values)
     tres = np.abs(DOE.res.params.values / bres)
     pt = 2 * t.pdf(tres, nr)
     fig = Figure()
     ax = fig.add_subplot(111)
     if self.coefradioButton.isChecked():
         if DOE.res.params.index[0] == 'Intercept':
             ind = np.arange(1, len(DOE.res.params))
             vcol = []
             for i in ind:
                 if (DOE.res.pvalues[i] < 0.05): vcol.append('red')
                 else: vcol.append('blue')
             ax.bar(ind, DOE.res.params[1:], align='center', color=vcol)
             ax.set_title('Coefficient Value : Intercept {:10.4f}-{:10.4f}-{:10.4f}'.\
             format(DOE.res.conf_int().ix[0,0],DOE.res.params[0],DOE.res.conf_int().ix[0,1]))
             ax.set_xticklabels(DOE.res.params.index[1:],
                                rotation='vertical')
             cmin = DOE.res.params[1:] - DOE.res.conf_int().ix[1:, 0]
             cmax = DOE.res.conf_int().ix[1:, 1] - DOE.res.params[1:]
             ax.errorbar(ind,
                         DOE.res.params[1:],
                         yerr=[cmin.values, cmax.values],
                         fmt='o',
                         ecolor='green')
         else:
             ind = np.arange(1, len(DOE.res.params) + 1)
             ax.bar(ind, DOE.res.params, align='center')
             ax.set_title('Coefficient Value : None Intercept')
             ax.set_xticklabels(DOE.res.params.index[0:],
                                rotation='vertical')
             cmin = DOE.res.conf_int().ix[0:, 0] - DOE.res.params[0:]
             cmax = DOE.res.conf_int().ix[0:, 1] - DOE.res.params[0:]
             ax.errorbar(ind,
                         DOE.res.params[0:],
                         yerr=[cmin.values, cmax.values],
                         fmt='o',
                         ecolor='green')
         ax.set_xticks(ind)
         ax.set_xlabel('Coefficient Number (except Intercept)')
         ax.annotate('red bar: significance 5%',
                     xy=(0.75, 0.95),
                     xycoords='figure fraction',
                     fontsize=8)
     elif self.coefpredradioButton.isChecked():
         if DOE.res.params.index[0] == 'Intercept':
             ind = np.arange(1, len(DOE.res.params))
             vcol = []
             for i in ind:
                 if (pt[i] < 0.05): vcol.append('red')
                 else: vcol.append('blue')
             ax.bar(ind, DOE.res.params[1:], align='center', color=vcol)
             ax.set_title(
                 'Coefficient Value : Intercept {:10.4f}-{:10.4f}-{:10.4f}'.
                 format(DOE.res.params[0] - tres[0] * bres[0] / np.sqrt(nr),
                        DOE.res.params[0], DOE.res.params[0] +
                        tres[0] * bres[0] / np.sqrt(nr)))
             ax.set_xticklabels(DOE.res.params.index[1:],
                                rotation='vertical')
             ax.errorbar(ind,
                         DOE.res.params[1:],
                         yerr=tres[1:] * bres[1:] / np.sqrt(nr),
                         fmt='o',
                         ecolor='green')
         else:
             ind = np.arange(1, len(DOE.res.params) + 1)
             ax.bar(ind, DOE.res.params, align='center')
             ax.set_title('Coefficient Value : None Intercept')
             ax.set_xticklabels(DOE.res.params.index[0:],
                                rotation='vertical')
             ax.errorbar(ind,
                         DOE.res.params[0:],
                         yerr=tres[0:] * bres[0:] / np.sqrt(nr),
                         fmt='o',
                         ecolor='green')
         ax.set_xticks(ind)
         ax.set_xlabel('Coefficient Number (except Intercept)')
         ax.annotate('red bar: significance 5%',
                     xy=(0.75, 0.95),
                     xycoords='figure fraction',
                     fontsize=8)
     elif self.fitradioButton.isChecked():
         yf = DOE.res.fittedvalues.tolist()
         resid = DOE.res.resid.tolist()
         ax.scatter(y, yf, color='red', alpha=0.3, marker='o')
         ax.set_ylabel('Fitted Values', color='red')
         ax.tick_params('y', colors='red')
         ax1 = ax.twinx()
         ax1.scatter(y, resid, color='blue', alpha=0.3, marker='o')
         ax1.set_ylabel('Residuals', color='blue')
         ax1.tick_params('y', colors='blue')
         xmin, xmax = ax.get_xlim()
         ax.set_ylim([xmin, xmax])
         df = DOE.res.df_resid
         vares = np.sum(DOE.res.resid**2) / df
         rmsef = np.sqrt(vares)
         vary = np.var(y.values)
         evar = (1 - vares / vary) * 100
         ax.set_title(
             'df {:3.0f};   RMSEF {:6.2f};   Exp.Var.{:5.1f}%'.format(
                 df, rmsef, evar))
         ax.add_line(Line2D([xmin, xmax], [xmin, xmax], color='red'))
         ax1.add_line(Line2D([xmin, xmax], [0, 0], color='blue'))
         ax.set_xlabel('Measured Values')
         if self.VcheckBox.isChecked():
             Lr = DOE.res.model.data.row_labels
             for i, txt in enumerate(Lr):
                 ax.annotate(str(txt), (y.ix[i], yf[i]))
     elif self.predradioButton.isChecked():
         ax.scatter(y, ypcv, color='red', alpha=0.3, marker='o')
         ax.set_ylabel('CV Predicted Values', color='red')
         ax.tick_params('y', colors='red')
         ax1 = ax.twinx()
         ax1.scatter(y, rcv, color='blue', alpha=0.3, marker='o')
         ax1.set_ylabel('CV Residuals', color='blue')
         ax1.tick_params('y', colors='blue')
         xmin, xmax = ax.get_xlim()
         ax.set_ylim([xmin, xmax])
         ax.set_xlabel('Measured Values')
         df = DS.Raw.shape[0]
         varcv = np.sum(np.array(rcv)**2) / df
         rmsecv = np.sqrt(varcv)
         vary = np.var(y.values)
         evar = (1 - varcv / vary) * 100
         ax.set_title(
             'df {:3.0f};   RMSECV {:6.2f};   Exp.Var.{:5.1f}%'.format(
                 df, rmsecv, evar))
         ax.add_line(Line2D([xmin, xmax], [xmin, xmax], color='red'))
         ax1.add_line(Line2D([xmin, xmax], [0, 0], color='blue'))
         if self.VcheckBox.isChecked():
             Lr = DOE.res.model.data.row_labels
             for i, txt in enumerate(Lr):
                 ax.annotate(str(txt), (y.ix[i], ypcv[i]))
     elif self.levradioButton.isChecked():
         Ftable = surtabDlg.launch(None)
         if len(np.shape(Ftable)) == 0: return ()
         if np.argmax(Ftable['X axis'].values) == np.argmax(
                 Ftable['Y axis'].values):
             QtWidgets.QMessageBox.critical(self,'Error',"Two variables on the same axis",\
                                            QtWidgets.QMessageBox.Ok)
             return ()
         fig = plt.figure()
         ax = fig.add_subplot(111)
         npts = 20
         xname = Ftable[(Ftable['X axis'] == True).values].index[0]
         yname = Ftable[(Ftable['Y axis'] == True).values].index[0]
         cname = Ftable[(Ftable['Constant'] == True).values].index.tolist()
         cvalue = Ftable.loc[(Ftable['Constant'] == True).values, 'value']
         zname = Yname
         x = np.linspace(float(Ftable['min'][xname]),
                         float(Ftable['max'][xname]), npts)
         y = np.linspace(float(Ftable['min'][yname]),
                         float(Ftable['max'][yname]), npts)
         px = []
         py = []
         for i in range(npts):
             for j in range(npts):
                 px.append(x[i])
                 py.append(y[j])
         data = pd.DataFrame({xname: px, yname: py, zname: px})
         xtitle = ''
         for i in range(len(cname)):
             xtitle = xtitle + cname[i] + ' = ' + str(
                 cvalue.values.tolist()[i])
             data[cname[i]] = np.ones(npts**2) * float(cvalue[i])
         my, mx = dmatrices(desc, data, return_type='dataframe')
         pz = np.diag(np.dot(np.dot(mx, dism), mx.T))
         px = np.array(px)
         py = np.array(py)
         pz = np.array(pz)
         z = plt.mlab.griddata(px, py, pz, x, y, interp='linear')
         plt.contour(x, y, z, 15, linewidths=0.5, colors='k')
         plt.contourf(x, y, z, 15, cmap=plt.cm.rainbow)
         plt.colorbar()
         ax.set_xlabel(xname)
         ax.set_ylabel(yname)
         ax.set_title(xtitle)
         ax.set_xlim([px.min(), px.max()])
         ax.set_ylim([py.min(), py.max()])
     elif self.surradioButton.isChecked():
         Ftable = surtabDlg.launch(None)
         if len(np.shape(Ftable)) == 0: return ()
         if np.argmax(Ftable['X axis'].values) == np.argmax(
                 Ftable['Y axis'].values):
             QtWidgets.QMessageBox.critical(self,'Error',"Two variables on the same axis",\
                                            QtWidgets.QMessageBox.Ok)
             return ()
         fig = plt.figure()
         ax = fig.add_subplot(111)
         npts = 100
         xname = Ftable[(Ftable['X axis'] == True).values].index[0]
         yname = Ftable[(Ftable['Y axis'] == True).values].index[0]
         cname = Ftable[(Ftable['Constant'] == True).values].index.tolist()
         cvalue = Ftable.loc[(Ftable['Constant'] == True).values, 'value']
         zname = Yname
         x = np.linspace(float(Ftable['min'][xname]),
                         float(Ftable['max'][xname]), npts)
         y = np.linspace(float(Ftable['min'][yname]),
                         float(Ftable['max'][yname]), npts)
         px = []
         py = []
         for i in range(npts):
             for j in range(npts):
                 px.append(x[i])
                 py.append(y[j])
         data = pd.DataFrame({xname: px, yname: py, zname: px})
         xtitle = ''
         for i in range(len(cname)):
             xtitle = xtitle + cname[i] + ' = ' + str(
                 cvalue.values.tolist()[i])
             data[cname[i]] = np.ones(npts**2) * float(cvalue[i])
         my, mx = dmatrices(desc, data, return_type='dataframe')
         pz = DOE.res.predict(mx)
         px = np.array(px)
         py = np.array(py)
         pz = np.array(pz)
         z = plt.mlab.griddata(px, py, pz, x, y, interp='linear')
         plt.contour(x, y, z, 15, linewidths=0.5, colors='k')
         plt.contourf(x, y, z, 15, cmap=plt.cm.rainbow)
         plt.colorbar()
         ax.set_xlabel(xname)
         ax.set_ylabel(yname)
         ax.set_title(xtitle)
         ax.set_xlim([px.min(), px.max()])
         ax.set_ylim([py.min(), py.max()])
     elif self.dismradioButton.isChecked():
         fig = plt.figure()
         ax = fig.add_subplot(111)
         cax = ax.matshow(dism)
         fig.colorbar(cax)
         ax.set_title('Trace = {:10.4f}'.format(np.trace(dism)))
     elif self.inflradioButton.isChecked():
         mxc = preprocessing.scale(mx.values,
                                   with_mean=True,
                                   with_std=False)
         mxc2 = mxc**2
         infl = np.sum(mxc2, axis=0) * np.diag(dism)
         fig = plt.figure()
         ax = fig.add_subplot(111)
         cax = ax.matshow(infl.reshape(1, -1), cmap='gray_r')
         fig.colorbar(cax)
         ax.yaxis.grid(False)
         ax.tick_params(axis='y',
                        which='both',
                        left='off',
                        right='off',
                        labelleft='off')
         ax.set_xlabel('Inlaction Factor')
     if self.XcheckBox.isChecked():
         if self.XlineEdit.text():
             ax.set_xlabel(self.XlineEdit.text())
     else:
         ax.set_xlabel('')
     if self.YcheckBox.isChecked():
         if self.YlineEdit.text():
             ax.set_ylabel(self.YlineEdit.text())
     else:
         ax.set_ylabel('')
     if self.XGcheckBox.isChecked():
         ax.xaxis.grid(True)
     else:
         ax.xaxis.grid(False)
     if self.YGcheckBox.isChecked():
         ax.yaxis.grid(True)
     else:
         ax.yaxis.grid(False)
     if not self.XMcheckBox.isChecked():
         ax.tick_params(axis='x',
                        which='both',
                        bottom='off',
                        top='off',
                        labelbottom='off')
     if not self.YMcheckBox.isChecked():
         ax.tick_params(axis='y',
                        which='both',
                        left='off',
                        right='off',
                        labelleft='off')
     self.rmmpl()
     self.addmpl(fig)
예제 #25
0
    def __init__(self, master, data=None):
        '''Create all frames, buttons and labels'''

        if type(data) not in plottable:
            self.inDictionary = data
            data = None

        self.master = master

        if data is None:
            data = np.arange(1)

        if data.ndim == 1:
            data = np.atleast_2d(data).T
        self.numData = data.shape[1]

        # Generate the figure -------------------------------------------
        fig, self.axs = plt.subplots(nrows=self.numData,
                                     sharex=True,
                                     sharey=False)

        if self.numData == 1:
            self.axs = [self.axs]

        self.lines = []
        self.rects = []
        self.zeros = []
        for ii in range(self.numData):
            self.lines.append(self.axs[ii].plot(data[:, ii]))

            # Zero line
            self.zeros.append(self.axs[ii].hlines(0,
                                                  0,
                                                  len(data),
                                                  linestyle='dotted'))

            # Zoom box
            self.epsilon = 5
            (x0, x1, y0, y1) = (0, 0, 0, 0)
            self.rects.append(
                Line2D([x0, x1, x1, x0, x0], [y0, y0, y1, y1, y0],
                       linestyle='dotted'))
            self.axs[ii].add_line(self.rects[-1])

        # Create the canvas
        self.canvas = FigureCanvasTkAgg(fig, master=master)
        self.canvas.show()
        self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)

        # Keyboard and mouse control
        self.button = False
        self.marks = []
        self.canvas.mpl_connect('key_press_event', self.on_key_event)
        self.canvas.mpl_connect('button_press_event', self.onclick)
        self.canvas.mpl_connect('button_release_event', self.onrelease)
        self.canvas.mpl_connect('motion_notify_event', self.onmotion)

        # Create and pack the widgets
        self.createWidgets()
        self.showAll()

        if 'inDictionary' in dir(self):
            self.selectPlotVar()
axs[1, 1].spines['right'].set_visible(False)
axs[1, 1].spines['top'].set_visible(False)
axs[1, 1].yaxis.set_ticks_position('left')
axs[1, 1].xaxis.set_ticks_position('bottom')

axs[1, 1].set_xticks([1.1, 2.1, 3.1])
axs[1, 1].set_xticklabels(['A', 'B', 'C'])
axs[1, 1].set_ylim(0, 20)
axs[1, 1].set_yticks([0, 5, 10, 15, 20])
axs[1, 1].set_ylabel('Min. and max $T_z$  along 20-yr contour (s)')

handles = []
for i in range(n_contributions):
    handles.append(
        Line2D([0], [0], marker=marker_class[classes[i]], c='w', ms=7,
               markerfacecolor=colors_for_contribution[i],
               markeredgecolor='k', alpha=0.7, linewidth=0.3))
handles.append(Line2D([0], [0], c='k', ls='--', dashes=(2,1)))
handles.append(Line2D([0], [0], c='k'))

labels = legends_for_contribution.copy()
labels.append('Empirical marginal 1-yr return value')
labels.append('Max/Min in full dataset')
fig_abc.legend(handles=handles, labels=labels,
           prop={'size': 6}, loc='lower center', ncol=7, scatterpoints=1)
fig_abc.tight_layout(rect=(0, 0.05, 1, 1))

# Plot the figure for datasets D, E F.
fig_def, axs = plt.subplots(2, 2, figsize=(10*0.75, 9*0.75))

# First, plot the 1-yr maxima.
예제 #27
0
def runSlices(opsimName, metadata, simdata, fields, bins, args, opsDb, verbose=False):
    # Set up the movie slicer.
    movieslicer = setupMovieSlicer(simdata, bins)
    # Set up formatting for output suffix.
    sliceformat = '%s0%dd' %('%', int(np.log10(len(movieslicer)))+1)
    # Get the telescope latitude info.
    lat_tele = Site(name='LSST').latitude_rad
    # Run through the movie slicer slicePoints and generate plots at each point.
    for i, ms in enumerate(movieslicer):
        t = time.time()
        slicenumber = sliceformat %(i)
        if verbose:
            print slicenumber
        # Set up metrics.
        if args.movieStepsize != 0:
            tstep = args.movieStepsize
        else:
            tstep = ms['slicePoint']['binRight'] - bins[i]
            if tstep > 1:
                tstep = 40./24./60./60.
        # Add simple view of time to plot label.
        times_from_start = ms['slicePoint']['binRight'] - (int(bins[0]) + 0.16 - 0.5)
        # Opsim years are 365 days (not 365.25)
        years = int(times_from_start/365)
        days = times_from_start - years*365
        plotlabel = 'Year %d Day %.4f' %(years, days)
        # Set up metrics.
        metricList, plotDictList = setupMetrics(opsimName, metadata, plotlabel=plotlabel,
                                    t0=ms['slicePoint']['binRight'], tStep=tstep, years=years, verbose=verbose)
        # Identify the subset of simdata in the movieslicer 'data slice'
        simdatasubset = simdata[ms['idxs']]
        # Set up opsim slicer on subset of simdata provided by movieslicer
        opslicer = slicers.OpsimFieldSlicer()
        # Set up metricBundles to combine metrics, plotdicts and slicer.
        bundles = []
        sqlconstraint = ''
        for metric, plotDict in zip(metricList, plotDictList):
            bundles.append(metricBundles.MetricBundle(metric, opslicer, sqlconstraint=sqlconstraint,
                                                      metadata=metadata, runName=opsimName,
                                                      plotDict=plotDict))
        # Remove (default) stackers from bundles, because we've already run them above on the original data.
        for mb in bundles:
            mb.stackerList = []
        bundledict = metricBundles.makeBundlesDictFromList(bundles)
        # Set up metricBundleGroup to handle metrics calculation + plotting
        bg = metricBundles.MetricBundleGroup(bundledict, opsDb, outDir=args.outDir, resultsDb=None, saveEarly=False)
        # 'Hack' bundleGroup to just go ahead and run the metrics, without querying the database.
        simData = simdatasubset
        bg.fieldData = fields
        bg.setCurrent(sqlconstraint)
        bg.runCurrent(sqlconstraint = sqlconstraint, simData=simData)
        # Plot data each metric, for this slice of the movie, adding slicenumber as a suffix for output plots.
        # Plotting here, rather than automatically via sliceMetric method because we're going to rotate the sky,
        #  and add extra legend info and figure text (for FilterColors metric).
        ph = plots.PlotHandler(outDir=args.outDir, figformat='png', dpi=72, thumbnail=False, savefig=False)
        obsnow = np.where(simdatasubset['expMJD'] == simdatasubset['expMJD'].max())[0]
        raCen = np.mean(simdatasubset[obsnow]['lst'])
        # Calculate horizon location.
        horizonlon, horizonlat = addHorizon(lat_telescope=lat_tele, raCen=raCen)
        # Create the plot for each metric and save it (after some additional manipulation).
        for mb in bundles:
            ph.setMetricBundles([mb])
            fignum = ph.plot(plotFunc=plots.BaseSkyMap(), plotDicts={'raCen':raCen})
            fig = plt.figure(fignum)
            ax = plt.gca()
            # Add horizon and zenith.
            plt.plot(horizonlon, horizonlat, 'k.', alpha=0.3, markersize=1.8)
            plt.plot(0, lat_tele, 'k+')
            # For the FilterColors metric, add some extra items.
            if mb.metric.name == 'FilterColors':
                # Add the time stamp info (plotlabel) with a fancybox.
                plt.figtext(0.75, 0.9, '%s' %(plotlabel), bbox=dict(boxstyle='Round, pad=0.7', fc='w', ec='k', alpha=0.5))
                # Add a legend for the filters.
                filterstacker = stackers.FilterColorStacker()
                for i, f in enumerate(['u', 'g', 'r', 'i', 'z', 'y']):
                    plt.figtext(0.92, 0.55 - i*0.035, f, color=filterstacker.filter_rgb_map[f])
                # Add a moon.
                moonRA = np.mean(simdatasubset[obsnow]['moonRA'])
                lon = -(moonRA - raCen - np.pi) % (np.pi*2) - np.pi
                moonDec = np.mean(simdatasubset[obsnow]['moonDec'])
                # Note that moonphase is 0-100 (translate to 0-1). 0=new.
                moonPhase = np.mean(simdatasubset[obsnow]['moonPhase'])/100.
                alpha = np.max([moonPhase, 0.15])
                circle = Circle((lon, moonDec), radius=0.05, color='k', alpha=alpha)
                ax.add_patch(circle)
                # Add some explanatory text.
                ecliptic = Line2D([], [], color='r', label="Ecliptic plane")
                galaxy = Line2D([], [], color='b', label="Galactic plane")
                horizon = Line2D([], [], color='k', alpha=0.3, label="20 deg elevation limit")
                moon = Line2D([], [], color='k', linestyle='', marker='o', markersize=8, alpha=alpha,
                              label="\nMoon (Dark=Full)\n         (Light=New)")
                zenith = Line2D([], [], color='k', linestyle='', marker='+', markersize=5, label="Zenith")
                plt.legend(handles=[horizon, zenith, galaxy, ecliptic, moon], loc=[0.1, -0.35], ncol=3, frameon=False,
                    title = 'Aitoff plot showing HA/Dec of simulated survey pointings', numpoints=1, fontsize='small')
            # Save figure.
            plt.savefig(os.path.join(args.outDir, mb.metric.name + '_' + slicenumber + '_SkyMap.png'), format='png', dpi=72)
            plt.close('all')
            dt, t = dtime(t)
        if verbose:
            print 'Ran and plotted slice %s of movieslicer in %f s' %(slicenumber, dt)
예제 #28
0
def induction_time_histograms_figure():
    ''' Plot the 4 histograms with the distribution of induction time.'''

    # Set font
    font = {'family': 'Arial', 'size': 10}
    rc('font', **font)

    # Make figure and grid.
    fig = plt.figure(figsize=(5.2, 2.7), tight_layout=True)
    gs = gridspec.GridSpec(2, 4, wspace=0.2, hspace=0.7, height_ratios=[3, 1])
    gs.tight_layout(fig)

    wl = -0.085  #width distance label
    hl = 1.2  #height distance label

    # Add all subfigures (MDS, 2DS, 3DS, 3DS zoomed)
    ax0 = fig.add_subplot(gs[2])
    ax0.text(wl, hl, 'C. 3DS', transform=ax0.transAxes, va='top', ha='left')
    histograms(ax0, DDDS, 'bistability/3DS/H500-600.csv', xlabel=False)
    ax0.tick_params(labelleft=False)

    ax = fig.add_subplot(gs[0], sharey=ax0)
    ax.text(wl, hl, 'A. MDS', transform=ax.transAxes, va='top', ha='left')
    histograms(ax, MDS, 'bistability/MDS/H500-600.csv', xlabel=False)

    ax = fig.add_subplot(gs[1], sharey=ax)
    ax.text(wl, hl, 'B. 2DS', transform=ax.transAxes, va='top', ha='left')
    histograms(ax, DDS, 'bistability/2DS/H500-600.csv')
    ax.tick_params(labelleft=False)

    ax = fig.add_subplot(gs[3], sharey=ax0)
    ax.text(wl,
            hl,
            'D. 3DS, zoomed',
            transform=ax.transAxes,
            va='top',
            ha='left')
    histograms(ax, DDDS, 'bistability/3DS/H500-600.csv', zoom=True)
    ax.tick_params(labelleft=False)

    # Plot legend.
    axleg = fig.add_subplot(gs[1, :])
    legend_elements = [
        Line2D([0], [0], color=colorp[0], lw=2, label='monotonic'),
        Line2D([0], [0], color=colorp[1], lw=2, label='non-monotonic 1'),
        Line2D([0], [0], color=colorp[2], lw=2, label='non-monotonic 2'),
        Line2D([0], [0], color=colorp[3], lw=2, label='non-monotonic 3'),
    ]

    axleg.legend(handles=legend_elements,
                 loc='upper center',
                 fontsize=10,
                 handlelength=1,
                 ncol=2,
                 frameon=False)
    axleg.axis('off')

    # Save and show figure
    #fig.savefig('Figures/bistabparhists-zoom.eps')

    plt.show()
예제 #29
0
        print()

        # collect plotting data
        bs.append(b)
        pred_snr.append(pred_out_snr_db)
        sim_snr.append(sim_out_snr_db)

    PREDS.append(pred_snr)
    SIMDS.append(sim_snr)
    IN_SNR.append(in_snr_db)

legend_elements = [
    Line2D([0], [0],
           marker='o',
           color='k',
           label='Evaluation',
           markerfacecolor='k',
           markersize=8,
           linestyle='-'),
    Line2D([0], [0],
           marker='s',
           color='k',
           label='Simulation',
           markerfacecolor='k',
           markersize=8,
           linestyle='--'),
]

fig, ax = plt.subplots(figsize=(10, 7))
for idx, nl in enumerate(noise_levels):
    ax.plot(bs,
 def __init__(self, ax, length, theta):
     self.length = length
     self.ax = ax
     self.line = Line2D([], [], marker='o')
     self.ax.add_line(self.line)
     self.theta = theta