Python matplotlib.pyplot.step() Examples
The following are 30
code examples of matplotlib.pyplot.step().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.pyplot
, or try the search function
.
Example #1
Source File: plot_util.py From DeepLearningSmells with Apache License 2.0 | 6 votes |
def save_precision_recall_curve(eval_labels, pred_labels, average_precision, smell, config, out_folder, dim, method): fig = plt.figure() precision, recall, _ = precision_recall_curve(eval_labels, pred_labels) step_kwargs = ({'step': 'post'} if 'step' in signature(plt.fill_between).parameters else {}) plt.step(recall, precision, color='b', alpha=0.2, where='post') plt.fill_between(recall, precision, alpha=0.2, color='b', **step_kwargs) plt.xlabel('Recall') plt.ylabel('Precision') plt.ylim([0.0, 1.05]) plt.xlim([0.0, 1.0]) if isinstance(config, cfg.CNN_config): title_str = smell + " (" + method + " - " + dim + ") - L=" + str(config.layers) + ", E=" + str(config.epochs) + ", F=" + str(config.filters) + \ ", K=" + str(config.kernel) + ", PW=" + str(config.pooling_window) + ", AP={0:0.2f}".format(average_precision) # plt.title(title_str) # plt.show() file_name = get_plot_file_name(smell, config, out_folder, dim, method, "_prc_") fig.savefig(file_name)
Example #2
Source File: plot_trajectories.py From Auto-PyTorch with Apache License 2.0 | 6 votes |
def plot_trajectory(plot_data, instance_name, metric_name, font_size, do_label_rename, plt, plot_individual, plot_markers, plot_type): for label, d in plot_data.items(): if do_label_rename: label = label_rename(label) if plot_individual and d["individual_trajectories"] and d["individual_times_finished"]: for individual_trajectory, individual_times_finished in zip(d["individual_trajectories"], d["individual_times_finished"]): plt.step(individual_times_finished, individual_trajectory, color=d["color"], where='post', linestyle=":", marker="x" if plot_markers else None) plt.step(d["finishing_times"], d["center"], color=d["color"], label=label, where='post', linestyle=d["linestyle"], marker="o" if plot_markers else None) plt.fill_between(d["finishing_times"], d["lower"], d["upper"], step="post", color=[(d["color"][0], d["color"][1], d["color"][2], 0.5)]) plt.xlabel('wall clock time [s]', fontsize=font_size) plt.ylabel('incumbent %s %s' % (metric_name, plot_type), fontsize=font_size) plt.legend(loc='best', prop={'size': font_size}) plt.title(instance_name, fontsize=font_size)
Example #3
Source File: classifier.py From Fake_News_Detection with MIT License | 6 votes |
def plot_PR_curve(classifier): precision, recall, thresholds = precision_recall_curve(DataPrep.test_news['Label'], classifier) average_precision = average_precision_score(DataPrep.test_news['Label'], classifier) plt.step(recall, precision, color='b', alpha=0.2, where='post') plt.fill_between(recall, precision, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.ylim([0.0, 1.05]) plt.xlim([0.0, 1.0]) plt.title('2-class Random Forest Precision-Recall curve: AP={0:0.2f}'.format( average_precision))
Example #4
Source File: km.py From DLF with MIT License | 6 votes |
def draw(num,zw_dict,maxb): """ draw the survival rate curve """ b_full_data=[] for i in range(1,maxb+1): b_full_data.append(win_prob(i,zw_dict)) s=range(1,maxb+1) A,=plt.step(s, b_full_data, 'r-',where='post',label=num,linewidth=1.0) font1 = {'family' : 'Times New Roman', 'weight' : 'normal', 'size' : 10, } tmp_data=np.array(b_full_data) tmp_data=1-tmp_data legend = plt.legend(handles=[A],prop=font1) plt.ylim((0,1)) plt.savefig(save_path+"/km_"+num) plt.close(1)
Example #5
Source File: plot_match_distrib.py From imips_open with GNU General Public License v3.0 | 6 votes |
def plot(dashed=False): print(hyperparams.methodEvalString()) _, true_inl, _, _, _ = cache.getOrEval() true_inl = sorted(true_inl) mscores = np.array(true_inl, dtype=float) / float(hyperparams.methodNPts()) yax = np.arange(len(mscores)).astype(float) / len(mscores) if dashed: style = '--' else: style = '-' plt.step(mscores, np.flip(yax), linestyle=style, label='%s: %.02f' % (hyperparams.label(), np.mean(mscores)), color=hyperparams.methodColor())
Example #6
Source File: plot_pose_accuracy.py From sips2_open with GNU General Public License v3.0 | 6 votes |
def plot(do_plot=True): hyperparams.announceEval() succ, Rerr, terr = cache_forward_pass.loadOrEvaluate() assert Rerr is not None sx, sy = evaluate.lessThanCurve(succ) sauc = evaluate.auc(sx, sy, 200) rx, ry = evaluate.lessThanCurve(Rerr) if FLAGS.ds == 'eu': print('5 degrees') rmax = 5 else: rmax = 1 rauc = evaluate.auc(rx, ry, rmax) tx, ty = evaluate.lessThanCurve(terr) tauc = evaluate.auc(tx, ty, 1) if do_plot: plt.step( rx, ry, label='%s R: %.2f' % (hyperparams.methodString(), rauc)) plt.step( tx, ty, label='%s t: %.2f' % (hyperparams.methodString(), tauc)) return sauc, rauc, tauc
Example #7
Source File: utils.py From DIAG-NRE with MIT License | 6 votes |
def plot_multi_agg_pr_curves(line_name2pr_list, plot_title='Aggregated Precision-Recall Curve', figsize=(12, 8), xlim=(0, 1), ylim=(0, 1), basic_font_size=14): plt.figure(figsize=figsize) for line_name, (prec_list, recall_list) in line_name2pr_list.items(): plt.step(recall_list, prec_list, label=line_name) plt.legend(fontsize=basic_font_size) plt.title(plot_title, fontsize=basic_font_size+ 2) plt.xlabel('Recall', fontsize=basic_font_size) plt.ylabel('Precision', fontsize=basic_font_size) plt.xticks(fontsize=basic_font_size) plt.yticks(fontsize=basic_font_size) plt.grid(True) plt.xlim(xlim) plt.ylim(ylim)
Example #8
Source File: plot_profiles.py From cosipy with GNU General Public License v3.0 | 5 votes |
def plot_profile(filename, pdate, lat, lon): """ This creates a simple plot showing the 2D fields""" DATA = xr.open_dataset(filename) (c_y, c_x) = naive_fast(DATA.lat.values, DATA.lon.values, lat, lon) DATA = DATA.sel(time=pdate,west_east=c_x,south_north=c_y) plt.figure(figsize=(20, 12)) depth = np.append(0,np.cumsum(DATA.LAYER_HEIGHT.values)) rho = np.append(DATA.LAYER_RHO[0],DATA.LAYER_RHO.values) plt.step(rho,depth) ax = plt.gca() ax.invert_yaxis() plt.show()
Example #9
Source File: out_of_sample_analysis.py From professional-services with Apache License 2.0 | 5 votes |
def compute_and_print_pr_auc(labels, probabilities, output_path=None): """Computes statistic on predictions, based on true labels. Prints precision-recall curve AUC and writes the curve as a PNG image to the specified directory. Args: labels: np.array, vector containing true labels. probabilities: np.array, 2-dimensional vector containing inferred probabilities. output_path: string, path to output directory. """ average_precision = average_precision_score(labels, probabilities[:, 1]) precision, recall, _ = precision_recall_curve(labels, probabilities[:, 1]) plt.step(recall, precision, color='b', alpha=0.2, where='post') plt.fill_between(recall, precision, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.ylim([0.0, 1.05]) plt.xlim([0.0, 1.0]) plt.title('Precision-Recall curve: AUC={0:0.2f}'.format(average_precision)) if output_path: full_path_jpg = os.path.join(output_path, 'pr_curve.png') plt.savefig(full_path_jpg) full_path_log = os.path.join(output_path, 'pr_auc.txt') with open(full_path_log, 'w+') as f: f.write('Precision-Recall AUC: {0:0.2f}\n'.format(average_precision)) f.write('Precision-Recall curve exported to: {}'.format(full_path_jpg))
Example #10
Source File: empirical_distribution.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, x, side='right'): step = True if step: #TODO: make this an arg and have a linear interpolation option? x = np.array(x, copy=True) x.sort() nobs = len(x) y = np.linspace(1./nobs,1,nobs) super(ECDF, self).__init__(x, y, side=side, sorted=True) else: return interp1d(x,y,drop_errors=False,fill_values=ival)
Example #11
Source File: plot.py From delta with Apache License 2.0 | 5 votes |
def plot_pr(precision, recall, thresholds, save_path): # pylint: disable=unused-argument ''' thresholds from low to hight ''' plt.figure() plt.step(recall, precision, color='b', alpha=0.2, where='post') plt.fill_between(recall, precision, step='post', alpha=0.2, color='b') plt.ylim([0.0, 1.05]) plt.xlim([0.0, 1.0]) plt.xlabel('Recall') plt.ylabel('Precision') plt.title('2-class Precision-Recall curve') plt.legend(loc='lower right') # pylint: disable=pointless-string-statement ''' # create the axis of thresholds (scores) thresholds = np.append(thresholds, 1.0) ax2 = plt.gca().twinx() ax2.plot(recall, thresholds, markeredgecolor='r', linestyle='dashed', color='r') ax2.set_ylabel('Threshold', color='r') ax2.set_ylim( [thresholds[0], thresholds[-1]] ) ax2.set_xlim( [recall[0], recall[-1]] ) ''' plt.savefig(save_path) plt.close()
Example #12
Source File: utils_squad_evaluate.py From fast-bert with Apache License 2.0 | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #13
Source File: evaluate-v2.0.py From ALBERT-TF2.0 with Apache License 2.0 | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #14
Source File: utils.py From DIAG-NRE with MIT License | 5 votes |
def plot_multi_pr_curves(plot_tuples, plot_title='Precision Recall Curves', figsize=(12, 8), xlim=(0, 1), ylim=(0, 1), basic_font_size=14): plt.figure(figsize=figsize) for eval_infos, line_name, line_color in plot_tuples: precs = eval_infos[0] recalls = eval_infos[1] avg_prec = eval_infos[3] f1_score = eval_infos[6] plt.step(recalls, precs, label=line_name + ' (AUC {0:.3f}, F1 {1:.3f})'.format(avg_prec, f1_score), color=line_color) dec_prec = eval_infos[4] dec_recall = eval_infos[5] plt.plot(dec_recall, dec_prec, 'o', color=line_color, markersize=8) plt.vlines(dec_recall, 0, dec_prec, linestyles='dashed', colors=line_color) plt.hlines(dec_prec, 0, dec_recall, linestyles='dashed', colors=line_color) plt.legend(fontsize=basic_font_size) plt.title(plot_title, fontsize=basic_font_size+ 2) plt.xlabel('Recall', fontsize=basic_font_size) plt.ylabel('Precision', fontsize=basic_font_size) plt.xticks(fontsize=basic_font_size) plt.yticks(fontsize=basic_font_size) plt.xlim(xlim) plt.ylim(ylim)
Example #15
Source File: ClassifierAnalyzer.py From CDSS with GNU General Public License v3.0 | 5 votes |
def plot_precision_recall_curve(self, title, dest_path): # Compute inputs. precisions, recalls, thresholds = self.compute_precision_recall_curve() average_precision = self._score_average_precision() # Set figure settings. rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['Helvetica', 'Arial', 'Tahoma'] # Make plot. plt.figure() plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') # Label axes. plt.xlabel('Recall') plt.ylabel('Precision') plt.ylim([0.0, 1.05]) plt.xlim([0.0, 1.0]) # Set title. plt.title('{0}: AP={1:0.2f}'.format(title, average_precision)) # Save figure. plt.savefig(dest_path) plt.close()
Example #16
Source File: squad_eval_v2.py From san_mrc with BSD 3-Clause "New" or "Revised" License | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #17
Source File: evaluate_v20.py From sotabench-eval with Apache License 2.0 | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #18
Source File: plot_profiles.py From cosipy with GNU General Public License v3.0 | 5 votes |
def plot_profile_1D(filename, pdate, d=None, lat=None, lon=None): """ This creates a simple plot showing the 2D fields""" DATA = xr.open_dataset(filename) DATA = DATA.sel(time=pdate) if ((lat is not None) & (lon is not None)): DATA = DATA.sel(lat=lat, lon=lon, method='nearest') plt.figure(figsize=(5, 5)) depth = np.append(0,np.cumsum(DATA.LAYER_HEIGHT.values)) if ((lat is None) & (lon is None)): rho = np.append(DATA.LAYER_RHO[:,:,0],DATA.LAYER_RHO.values) t = np.append(DATA.LAYER_T[:,:,0],DATA.LAYER_T.values) else: rho = np.append(DATA.LAYER_RHO[0],DATA.LAYER_RHO.values) t = np.append(DATA.LAYER_T[0],DATA.LAYER_T.values) print('Date: %s' % (pdate)) print('T2: %.2f \t RH: %.2f \t U: %.2f \t G: %.2f' % (DATA.T2,DATA.RH2,DATA.U2,DATA.G)) if (d is not None): for dmeas in d: #idx, val = find_nearest(depth,d) idx, val = find_nearest(depth,dmeas) print('nearest depth: %.3f \t density: %.2f \t T: %.2f' % (val,rho[idx],t[idx])) plt.step(rho,depth) ax1 = plt.gca() ax1.invert_yaxis() ax1.set_ylabel('Depth [m]') ax1.tick_params(axis='x', labelcolor='blue') ax1.set_xlabel('Density [kg m^-3]', color='blue') ax2 = ax1.twiny() ax2.plot(t,depth, color='red') ax2.set_xlabel('Temperature [K]', color='red') ax2.tick_params(axis='x', labelcolor='red') plt.show()
Example #19
Source File: squad_v2_official.py From claf with MIT License | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): # pragma: no cover plt.step(recalls, precisions, color="b", alpha=0.2, where="post") plt.fill_between(recalls, precisions, step="post", alpha=0.2, color="b") plt.xlabel("Recall") plt.ylabel("Precision") plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #20
Source File: squad_utils.py From xlnet with Apache License 2.0 | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #21
Source File: evaluate-v2.0.py From ReuBERT with MIT License | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #22
Source File: eval_squad.py From xlnet_extension_tf with Apache License 2.0 | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #23
Source File: mrc_eval.py From mt-dnn with MIT License | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #24
Source File: FlipFlop.py From fixed-point-finder with Apache License 2.0 | 5 votes |
def _plot_single_trial(input_txd, output_txd, pred_output_txd): VERTICAL_SPACING = 2.5 [n_time, n_bits] = input_txd.shape tt = range(n_time) y_ticks = [VERTICAL_SPACING*bit_idx for bit_idx in range(n_bits)] y_tick_labels = \ ['Bit %d' % (n_bits-bit_idx) for bit_idx in range(n_bits)] plt.yticks(y_ticks, y_tick_labels, fontweight='bold') for bit_idx in range(n_bits): vertical_offset = VERTICAL_SPACING*bit_idx # Input pulses plt.fill_between( tt, vertical_offset + input_txd[:, bit_idx], vertical_offset, step='mid', color='gray') # Correct outputs plt.step( tt, vertical_offset + output_txd[:, bit_idx], where='mid', linewidth=2, color='cyan') # RNN outputs plt.step( tt, vertical_offset + pred_output_txd[:, bit_idx], where='mid', color='purple', linewidth=1.5, linestyle='--') plt.xlim(-1, n_time)
Example #25
Source File: evaluations.py From Efficient-GAN-Anomaly-Detection with MIT License | 5 votes |
def do_prc(scores, true_labels, file_name='', directory='', plot=True): """ Does the PRC curve Args : scores (list): list of scores from the decision function true_labels (list): list of labels associated to the scores file_name (str): name of the PRC curve directory (str): directory to save the jpg file plot (bool): plots the PRC curve or not Returns: prc_auc (float): area under the under the PRC curve """ precision, recall, thresholds = precision_recall_curve(true_labels, scores) prc_auc = auc(recall, precision) if plot: plt.figure() plt.step(recall, precision, color='b', alpha=0.2, where='post') plt.fill_between(recall, precision, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.ylim([0.0, 1.05]) plt.xlim([0.0, 1.0]) plt.title('Precision-Recall curve: AUC=%0.4f' %(prc_auc)) if not os.path.exists(directory): os.makedirs(directory) plt.savefig('results/' + file_name + '_prc.jpg') plt.close() return prc_auc
Example #26
Source File: classification.py From Kaggler with MIT License | 5 votes |
def plot_pr_curve(y, p): precision, recall, _ = precision_recall_curve(y, p) plt.step(recall, precision, color='b', alpha=0.2, where='post') plt.fill_between(recall, precision, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.ylim([0.0, 1.05]) plt.xlim([0.0, 1.0])
Example #27
Source File: squad_evaluation.py From FARM with Apache License 2.0 | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #28
Source File: eval_squad_v2.0.py From pytorch_pretrained_BERT with Apache License 2.0 | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()
Example #29
Source File: empirical_distribution.py From vnpy_crypto with MIT License | 5 votes |
def __init__(self, x, side='right'): step = True if step: #TODO: make this an arg and have a linear interpolation option? x = np.array(x, copy=True) x.sort() nobs = len(x) y = np.linspace(1./nobs,1,nobs) super(ECDF, self).__init__(x, y, side=side, sorted=True) else: return interp1d(x,y,drop_errors=False,fill_values=ival)
Example #30
Source File: evaluate-v2.0.py From GPT2sQA with Apache License 2.0 | 5 votes |
def plot_pr_curve(precisions, recalls, out_image, title): plt.step(recalls, precisions, color='b', alpha=0.2, where='post') plt.fill_between(recalls, precisions, step='post', alpha=0.2, color='b') plt.xlabel('Recall') plt.ylabel('Precision') plt.xlim([0.0, 1.05]) plt.ylim([0.0, 1.05]) plt.title(title) plt.savefig(out_image) plt.clf()