def plot_cnot_prob(cnot):
    probs = cnot[0]
    x = [1, 2, 3, 4]
    rects = plt.bar(x, probs)
    for rect in rects:
        height = rect.get_height()
        plt.text(rect.get_x() + rect.get_width() / 2.,
                 1.05 * height,
                 f'{height:.3f}',
                 ha='center',
                 va='bottom')
    plt.xticklabels(['|00>', '|01>', '|10>', '|11>'])
    plt.set_ylim(0., 1.4)
    plt.show()
Esempio n. 2
0
def histogram(samples, xlabels, name=''):
    # distribution of examples per class displayed as a histogram
    plt.rcParams['figure.figsize'] = (8, 6)
    n, bins, patches = plt.hist(samples,
                                len(xlabels),
                                facecolor='green',
                                histtype='bar',
                                rwidth=0.8,
                                alpha=1)
    plt.grid(True)
    plt.xticklabels(xlabels)

    if name and not name.isspace():
        plt.savefig(name)
def main():
    fig = plt.figure(figsize=(15, 10))

    data = {}
    files = []
    for file in glob.glob("*.dat"):
        files.append(file)

    files = sorted(files, key=lambda x: int(x.split('_')[-1].split('.')[0]))

    for file in files:
        with open(file, 'r') as f:
            file_number = int(file.split('_')[-1].split('.')[0])
            data[file_number] = []

            for line in f.readlines():
                dat = line.split()[-1]
                data[file_number].append(float(dat))

            # plot and annotate histograms
            y, x, _ = plt.hist(data[file_number], bins=100, histtype='step')
            y_coord = max(y)

            x_coord = x[np.where(y == max(y))[0][0]]
            plt.annotate(str(file_number), (x_coord, y_coord), ha='center')

    plt.xlabel('dihedral angle')
    plt.ylabel('frequency')
    xticks = np.arange(-130, 50, 15)
    plt.xticks(xticks)
    plt.xticklabels([str(k) + "°" for k in xticks])

    #  use quantiles to check proper overlap of distributions
    with open('umbrella_stats.txt', 'w') as o:
        o.write('file number <-> filenumber : sufficient overlap\n')
        for key in sorted(data.keys()):
            key_next = key + 1
            if key_next in data.keys():
                dat = np.asarray(data[key])
                dat_next = np.asarray(data[key_next])
                dat_quantile = np.quantile(dat, 0.8)
                dat_next_quantile = np.quantile(dat_next, 0.2)
                # plt.axvline(dat_quantile, color='red')
                # plt.axvline(dat_next_quantile)
                if (dat_quantile > dat_next_quantile):
                    o.write('{} <-> {} : True\n'.format(key, key_next))
                else:
                    print('!!! {} <-> {} : False\n'.format(key, key_next))
                    o.write('{} <-> {} : False\n'.format(key, key_next))
    plt.savefig('histograms.png')
def sexyaxis(*args, **kwargs):
    a = xlim

    minf = a[1]
    maxf = a[2]
    possibles = arange(1, 50) * 2000
    if (maxf - minf) < 8000:
        possibles = possibles / 2
    ticks = array([])
    labels = []
    for i in range(1, size(possibles)):
        if (possibles[i] >= minf) and (possibles[i] <= maxf):
            ticks[end + 1] = possibles[i]
            labels[end + 1] = print('%d' % possibles[i])

    mpl.xticks(ticks)
    mpl.xticklabels(labels)
    return a
Esempio n. 5
0
metrics_ = []
for k in range(1000):
    X2_training, X2_testing, y2_training, y2_testing = train_test_split(X2, y_true, test_size=test_size)
    clf = GradientBoostingClassifier(**params)
    clf.fit(X2_training[:,89:], y2_training)
    metrics_ += [compute_metrics(y2_testing, clf.predict(X2_testing[:,89:]))]


print_metrics(y2_testing, clf.predict(X2_testing[:,89:]))
plt.xlabel('iteration')
plt.ylabel('Training loss')
plt.title('Training loss by considering just one frame 18h before eruption')
plt.plot(clf.train_score_)
plt.show()
plt.xlabel('Features')
plt.xticklabels()
plt.ylabel('Relative importance')
plt.plot(clf.feature_importances_, '+')
plt.show()
plt.xlabel('Nb of frames considered (time points)')
plt.ylabel('Accuracy')


# SVM (rbf kernel)
scaler = StandardScaler()
scaler.fit(X2_training)
# Best performance (acc, tss) for X_train: gamma = 7, kernel = rbf, C = 50
# Best performance (tss) for X2_train: gamma = 0.037, C = 24
clf = svm.SVC(C = 24, kernel='rbf', gamma =  0.037, tol = 1e-10)
clf.fit(scaler.transform(X2_training), y2_training)
scaler.fit(X2_testing)
    .max(),
    where=(df['data'] > '01/01') & (df['data'] < '03/31'),
    facecolor='blue',
    alpha=0.5)
plt.fill_between(
    df['data'],
    0,
    df['PSZ-AC:1 HEAT PUMP DX COOLING COIL:Cooling Coil Total Cooling Rate [W](TimeStep)']
    .max(),
    where=(df['data'] > '11/02') & (df['data'] < '12/31'),
    facecolor='blue',
    alpha=0.5)
plt.legend()
plt.xlabel('Date')
plt.xticks(df['data'][::30])
plt.xticklabels(df['data'][::30], rotation=45)
# plt.xticks(df['data'])
plt.title('Heat pump Heating and Cooling coil rate')
plt.show()

# Prova 2: con ax.
fig, ax = plt.subplots()
ax.bar(
    df['data'],
    df['PSZ-AC:1 HEAT PUMP DX HEATING COIL:Heating Coil Heating Rate [W](TimeStep)'],
    color='blue',
    label='Coil Heating Rate [W]')
# df.plot(x='data', y=['PSZ-AC:1 HEAT PUMP DX COOLING COIL:Cooling Coil Total Cooling Rate [W](TimeStep)', 'PSZ-AC:1 HEAT PUMP DX HEATING COIL:Heating Coil Heating Rate [W](TimeStep)'])
ax.bar(
    df['data'],
    df['PSZ-AC:1 HEAT PUMP DX COOLING COIL:Cooling Coil Total Cooling Rate [W](TimeStep)'],
Esempio n. 7
0
    ax[1].set_xlabel('Time (ms)')
    ax[1].set_ylabel('Channel')
    ax[1].axvline(x=30, color='black')
    ax[1].set_title('larger boundary ' + band)
    fig.subplots_adjust(right=0.8)
    cbar_ax = fig.add_axes([0.85, 0.15, 0.03, 0.7])
    fig.colorbar(img, cax=cbar_ax)


plotbydrift('highbeta', 2)

plt.legend()

x_label_list = np.arange(-300, 600, 100)
plt.xticks(np.arange(0, 90, 10))
plt.xticklabels(x_label_list)
plt.set_xlabel('Time (ms)')
plt.set_ylabel('Power')


def runplot(var1):
    easy, med, hard = np.arange(0, 33), np.arange(33, 66), np.arange(66, 99)
    condlist = [easy, med, hard]
    titlelist = ['easy', 'med', 'hard']
    fig, ax = plt.subplots(1, 3, figsize=(17, 5))
    fig.tight_layout(pad=2)

    for i in range(0, 3):
        cond = condlist[i]
        # limit = max(abs(np.min(theta_fast)), abs(np.max(theta_fast)))
        mat = np.mean(band_dic[var1][cond], axis=0)
Esempio n. 8
0
def make_plot(data_to_plot,
              colors_to_plot,
              plot_title,
              filename,
              sub_dir='',
              xlim=(-50, 50),
              xticks=[-40, -20, 0, 20, 40],
              ylim=(29, 71),
              yticks=[30, 40, 50, 60, 70],
              yline=50,
              plot_yline=True,
              legend_labels=[],
              xtick_labels=[],
              xlabel='Distance to TSS (kb), Txn L-->R',
              ylabel='% of forks moving L-->R',
              legend_loc='lower right'):
    plt.figure(figsize=(fig_size_width, fig_size_height), dpi=300)

    for i, data in enumerate(data_to_plot):
        color = colors_to_plot[i]
        if (len(legend_labels) > 0):
            lab = legend_labels[i]
        else:
            lab = ''
        plt.plot(
            range(int(-1 * length_around_site / 2),
                  int(length_around_site / 2 + 1)),
            data,
            '-',
            color=color,
            label=lab,
            linewidth=1.25,
        )

    if (len(ylim) == 2):
        plt.ylim(ylim)
        if (len(yticks) > 0):
            plt.yticks(yticks)

    if (len(xlim) == 2):
        plt.xlim(xlim)
        if (len(xticks) > 0):
            plt.xticks(xticks)
        if (len(xtick_labels) > 0):
            plt.xticklabels(xtick_labels)

    plt.title(plot_title, x=0.02, y=0.9, ha='left', va='top')
    if (plot_yline == True):
        plt.axhline(y=yline, color='black', linewidth=0.8, dashes=[2, 4])
    plt.axvline(linestyle='--', color='black', linewidth=0.8, dashes=[2, 4])
    if (len(legend_labels) > 0):
        if (legend_loc == 'lower right'):
            legend = plt.legend(loc='lower right',
                                fancybox=False,
                                bbox_to_anchor=(1.03, -0.035))
        elif (legend_loc == 'upper right'):
            legend = plt.legend(loc='upper right',
                                fancybox=False,
                                bbox_to_anchor=(1.03, 1.035))
        else:
            legend = plt.legend(loc=legend_loc)
        frame = legend.get_frame()
        frame.set_linewidth(0.6)
        frame.set_edgecolor('black')

    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.tight_layout(pad=2)
    plt.savefig(base_dir + '/' + sub_dir + '/' + filename + '.' + ext,
                transparent=True)
    plt.clf()
    plt.close()