Beispiel #1
0
def cv_bp(cv_df, title, axes):
    axes.grid(b=True,
              which='both',
              axis='both',
              color='grey',
              linestyle='--',
              linewidth='0.3')
    sns.boxplot(x='model_name',
                y='roc_auc',
                data=cv_df,
                width=0.5,
                ax=axes,
                palette=current_palette).set_title(title)
    sns.stripplot(x='model_name',
                  y='roc_auc',
                  data=cv_df,
                  size=5,
                  jitter=True,
                  edgecolor="grey",
                  linewidth=1,
                  ax=axes)
    plt.ylim(0.2, 1)
    plt.savefig('{}.png'.format(title), format='png')
def plot_graph(train_history, label_col, mode):

    # Obtain scores from history
    loss = train_history.history['loss'] #List
    val_loss = train_history.history['val_loss']

    #Check if binary or multiclass problem to obtain correct metrics
    if mode == 0:
        acc = train_history.history['binary_accuracy']
        val_acc = train_history.history['val_binary_accuracy']
    else:
        acc = train_history.history['categorical_accuracy']
        val_acc = train_history.history['val_categorical_accuracy']

    # Plot loss scores
    sns.set_style("whitegrid")
    fig, ax = plt.subplots(1, 1)
    ax.plot(loss, label = "Loss")
    ax.plot(val_loss, label = "Validation Loss")
    ax.set_title('Model Loss')
    ax.legend(loc = "upper right")
    ax.set_xlim([0, 100])
    ax.set_ylabel("Loss")
    ax.set_xlabel("Epochs")
    ax.minorticks_on()
    ax.grid(b=True, which='major')
    ax.grid(b=True, which='minor')
    plt.savefig(results_dir + '/' + label_col + '_loss.png')
    plt.show()

    # Plot accuracy scores
    fig, ax = plt.subplots(1, 1)
    ax.plot(acc, label = "Accuracy")
    ax.plot(val_acc, label = "Validation Accuracy")
    ax.set_title('Model Accuracy')
    ax.legend(loc = "lower right")
    ax.set_xlim([0, 100])
    ax.grid(b=True, which='major')
    ax.grid(b=True, which='minor')
    ax.set_ylabel("Accuracy")
    ax.set_xlabel("Epochs")
    ax.minorticks_on()
    plt.savefig(results_dir + '/' + label_col + '_acc.png')
    plt.show()
    return 0
    if len(resY3):
        plt.plot(resx3, resY3)
    if len(resY4):
        plt.plot(resx4, resY4)
    (supX1, supY1, supX2, supY2, supX3, supY3, supX4, supY4,
     supSlope) = computeSupportLines(low, timestamp)
    plt.plot(supX1, supY1)
    plt.plot(supX2, supY2)
    if len(supY3):
        plt.plot(supX3, supY3)
    if len(supY4):
        plt.plot(supX4, supY4)
    sys, resYs = [supY1, supY3, supY4], [resY1, resY3, resY4]
    (supYmVal, ascDescVal, riseFallVal,
     avgTouches) = detectTriangle([supY1, supY3, supY4], [resY1, resY3, resY4],
                                  high, low)

    mins, maxs = computePivotPoints(high, low, timestamp)
    for x, y in maxs:
        ax.plot(x, y)
    for x, y in mins:
        ax.plot(x, y)
    ax.xaxis.set_major_locator(mticker.MaxNLocator(10))
    plt.ylim(ymin=min(low), ymax=max(high) + max(high) * 0.05)
    ax.grid(True)
    plt.yscale('log')
    plt.xlabel('Date')
    plt.ylabel('Price')
    plt.title(args.symbol)
    plt.show()
def run(data):
    # update the data
    t,y = data
    if t>-1:
        xdata.append(t)
        ydata.append(y)
        #if t>xsize: # Scroll to the left.
           # ax.set_xlim(t-xsize, t)
        line.set_data(xdata, ydata)

    return line,

def on_close_figure(event):
    sys.exit(0)

data_gen.t = -1
fig = plt.figure()
fig.canvas.mpl_connect('close_event', on_close_figure)
ax = fig.add_subplot(111)
line, = ax.plot([], linestyle='-.', lw=7, color = 'red')
ax.set_ylim(0, 250)
ax.set_xlim(0, 400)
ax.grid()
xdata, ydata = [], []

# Important: Although blit=True makes graphing faster, we need blit=False to prevent
# spurious lines to appear when resizing the stripchart.
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=100, repeat=False)
plt.show()

Beispiel #5
0
def makeClocPlot(info_list, name):
    data = []
    code_lines = []
    comment_lines = []
    comment_percentage_lines = []
    comment_percentage_lines_max = []
    comment_percentage_lines_min = []

    debug_lines = []
    debug_percentage_lines = []
    debug_percentage_lines_max = []
    debug_percentage_lines_min = []

    #[print(cloc[x][0]) for x in range(0,5)]

    try:
        [
            data.append(DT.datetime.strptime(info_list[index][0], "%Y_%m_%d"))
            for index in range(0, n_cloc)
        ]
        #[print(cloc[x][2]) for x in range(0,5)]
    except Exception as ex:
        print(ex)

    [code_lines.append(info_list[index][2]) for index in range(0, n_cloc)]
    [comment_lines.append(info_list[index][3]) for index in range(0, n_cloc)]
    [
        comment_percentage_lines.append(info_list[index][5])
        for index in range(0, n_cloc)
    ]
    [
        comment_percentage_lines_max.append(info_list[index][6])
        for index in range(0, n_cloc)
    ]
    [
        comment_percentage_lines_min.append(info_list[index][8])
        for index in range(0, n_cloc)
    ]

    [debug_lines.append(info_list[index][4]) for index in range(0, n_cloc)]
    [
        debug_percentage_lines.append(info_list[index][10])
        for index in range(0, n_cloc)
    ]
    [
        debug_percentage_lines_max.append(info_list[index][11])
        for index in range(0, n_cloc)
    ]
    [
        debug_percentage_lines_min.append(info_list[index][13])
        for index in range(0, n_cloc)
    ]

    lines = []
    labels_fig = []

    #dates = mpdates.date2num(data)
    dates = []
    [dates.append(index) for index in range(0, n_cloc)]

    gs_top = plt.GridSpec(5, 1, top=0.95)
    fig, ((ax1, ax4), (ax2, ax5),
          (ax3, ax6)) = plt.subplots(3, 2, sharex=True,
                                     facecolor=light_grey_c)  #, sharey=True)

    ax1.plot_date(dates,
                  code_lines,
                  'r-',
                  label="Code lines",
                  lw=2,
                  color=red_c)
    ax1.set_title("Code lines:", weight="bold")

    ax2.plot_date(dates,
                  comment_lines,
                  'g-',
                  label="Comment lines",
                  lw=2,
                  color=yell_c)
    ax2.set_title("Comment lines:", weight="bold")

    ax3.plot_date(dates,
                  comment_percentage_lines,
                  'b-',
                  label="Comment % lines",
                  color=blue_c)
    ax3.plot_date(dates,
                  comment_percentage_lines_max,
                  'b--',
                  label="Comment % lines (max)",
                  color=blue_c)
    ax3.plot_date(dates,
                  comment_percentage_lines_min,
                  'b--',
                  label="Comment % lines (min)",
                  color=blue_c)

    ax4.axis('off')

    ax5.plot_date(dates,
                  debug_lines,
                  'm-',
                  label="Debug lines",
                  lw=2,
                  color=grey_c)
    ax5.set_title("Debug lines:", weight="bold")

    ax6.plot_date(dates,
                  debug_percentage_lines,
                  'c-',
                  label="Debug % lines",
                  color=green_c)
    ax6.plot_date(dates,
                  debug_percentage_lines_max,
                  'c--',
                  label="Debug % lines (max)",
                  color=green_c)
    ax6.plot_date(dates,
                  debug_percentage_lines_min,
                  'c--',
                  label="Debug % lines (min)",
                  color=green_c)

    handles_all = []
    labels_all = []
    for ax in ax1, ax2, ax3, ax4, ax5, ax6:
        ax.grid(True)
        ax.margins(0.08)  # 5% padding in all directions
        #ax.set_facecolor(light_grey_c)
        handles, labels = ax.get_legend_handles_labels()
        handles_all += handles
        labels_all += labels

    ax1.set_ylabel('Number of lines', weight="bold")
    ax2.set_ylabel('Number of lines', weight="bold")
    ax3.set_ylabel('Percentage', weight="bold")

    ax3.set_xlabel('  -->  Time  -->  ', weight="bold")
    ax6.set_xlabel('  -->  Time  -->  ', weight="bold")

    ax4.legend(handles_all[::1],
               labels_all[::1],
               loc="upper left",
               bbox_to_anchor=[0.15, 1.1],
               ncol=1,
               shadow=True,
               fancybox=True,
               fontsize=8)
    #fontsize : int or float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’}
    #title="Legend",

    #fig.suptitle(name)
    #fig.autofmt_xdate()
    fig.subplots_adjust(left=0.13,
                        bottom=0.11,
                        right=0.93,
                        top=0.92,
                        wspace=0.15,
                        hspace=0.25)

    plt.xticks([])
    plt.show()
    img_name = name
    img_name.replace(" ", "")
    img_name += ".png"
    fig.savefig(img_name, bbox_inches='tight')
Beispiel #6
0
    #q_1 = np.mean(dec_1_q[a:b])

    mag_0 = np.sqrt(i_0[s]**2 + q_0[s]**2)
    mag_1 = np.sqrt(i_1[s]**2 + q_1[s]**2)

    #mean_0_i.append(i_0)
    #mean_0_q.append(q_0)
    offset_0.append(mag_0)
    #mean_1_i.append(i_1)
    #mean_1_q.append(q_1)
    offset_1.append(mag_1)
    offset.append(mag_1 - mag_0)

nsubs = 4

ax.grid(which='major')

plt.subplot(nsubs, 1, 1)
plt.plot(data)
plt.title("Time domain audio wave")

#data_fft = np.fft.fft(np.array(data))
#frequencies = np.abs(data_fft)
#plt.subplot(nsubs,1,2)
#plt.plot(frequencies)
#plt.title("Frequencies found")
#plt.xlim(0,20000)

#plt.subplot(nsubs,1,2)
#plt.title("IQ Decode")
#plt.plot(range(nframes), dec_0_i, 'r', dec_0_q, 'g', dec_1_i, 'c', dec_1_q, 'b')