本文整理匯總了Python中matplotlib.pyplot.step方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.step方法的具體用法?Python pyplot.step怎麽用?Python pyplot.step使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.step方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save_precision_recall_curve
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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)
示例2: draw
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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)
示例3: plot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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())
示例4: plot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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
示例5: plot_PR_curve
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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))
示例6: plot_multi_agg_pr_curves
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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)
示例7: plot_trajectory
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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)
示例8: __call__
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
def __call__(self, args, env):
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import average_precision_score
from sklearn.metrics import precision_recall_curve
from vergeml.plots import load_labels, load_predictions
try:
labels = load_labels(env)
except FileNotFoundError:
raise VergeMLError("Can't plot PR curve - not supported by model.")
nclasses = len(labels)
if args['class'] not in labels:
raise VergeMLError("Unknown class: " + args['class'])
try:
y_test, y_score = load_predictions(env, nclasses)
except FileNotFoundError:
raise VergeMLError("Can't plot PR curve - not supported by model.")
# From:
# https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html#sphx-glr-auto-examples-model-selection-plot-precision-recall-py
ix = labels.index(args['class'])
y_test = y_test[:,ix].astype(np.int)
y_score = y_score[:,ix]
precision, recall, _ = precision_recall_curve(y_test, y_score)
average_precision = average_precision_score(y_test, y_score)
plt.step(recall, precision, color='b', alpha=0.2, where='post')
plt.fill_between(recall, precision, alpha=0.2, color='b', step='post')
plt.xlabel('Recall ({})'.format(args['class']))
plt.ylabel('Precision ({})'.format(args['class']))
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall curve for @{0}: AP={1:0.2f}'.format(args['@AI'], average_precision))
plt.show()
示例9: plot_pr_curve
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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])
示例10: plot_pr_curve
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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()
示例11: __init__
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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)
示例12: do_prc
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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
示例13: plot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
def plot(label=None, k=10):
hyperparams.announceEval()
eval_pairs = hyperparams.getEvalDataGen()
# Very special case lfnet:
if FLAGS.baseline == 'lfnet':
x = [50, 100, 150]
y = []
for num_pts in x:
forward_pass_dict = baselines.parseLFNetOuts(eval_pairs, num_pts)
success = np.zeros(len(eval_pairs), dtype=bool)
for pair_i in range(len(eval_pairs)):
pair = eval_pairs[pair_i]
folder, a, b = pair.name().split(' ')
forward_passes = [forward_pass_dict['%s%s' % (folder, i)]
for i in [a, b]]
matched_indices = system.match(forward_passes)
inliers = system.getInliers(
pair, forward_passes, matched_indices)
if np.count_nonzero(inliers) >= k:
success[pair_i] = True
y.append(np.mean(success.astype(float)))
plt.plot(x, y, 'x', label='%s: N/A' % (hyperparams.methodString()))
else:
pair_outs = cache_forward_pass.loadOrCalculateOuts()
if FLAGS.num_scales > 1 and FLAGS.baseline == '':
fps = [[multiscale.forwardPassFromHicklable(im) for im in pair]
for pair in pair_outs]
else:
fps = [[system.forwardPassFromHicklable(im) for im in pair]
for pair in pair_outs]
pairs_fps = zip(eval_pairs, fps)
stats = [evaluate.leastNumForKInliers(pair_fps[0], pair_fps[1], k)
for pair_fps in pairs_fps]
x, y = evaluate.lessThanCurve(stats)
auc = evaluate.auc(x, y, 200)
plt.step(x, y, label='%s: %.2f' % (hyperparams.label(), auc))
return auc
示例14: ecdf_plot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
def ecdf_plot(self):
"""Generate ECDF plot comparing distributions of the test classes."""
plt.figure()
for classname in self.data:
data = self.data.loc[:, classname]
levels = np.linspace(1. / len(data), 1, len(data))
plt.step(sorted(data), levels, where='post')
self.make_legend()
plt.title("Empirical Cumulative Distribution Function")
plt.xlabel("Time [s]")
plt.ylabel("Cumulative probability")
plt.savefig(join(self.output, "ecdf_plot.png"), bbox_inches="tight")
plt.close()
示例15: plot_pr_curve
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import step [as 別名]
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()