本文整理匯總了Python中pylab.legend方法的典型用法代碼示例。如果您正苦於以下問題:Python pylab.legend方法的具體用法?Python pylab.legend怎麽用?Python pylab.legend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pylab
的用法示例。
在下文中一共展示了pylab.legend方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: plot_learning_curve
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_learning_curve(train_sizes, train_scores, test_scores):
"""plot_learning_curve."""
plt.figure(figsize=(15, 5))
plt.title('Learning Curve')
plt.xlabel("Training examples")
plt.ylabel("AUC ROC")
tr_ys = compute_stats(train_scores)
te_ys = compute_stats(test_scores)
plot_stats(train_sizes, tr_ys,
label='Training score',
color='navy')
plot_stats(train_sizes, te_ys,
label='Cross-validation score',
color='orange')
plt.grid(linestyle=":")
plt.legend(loc="best")
plt.show()
示例2: plot_it
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_it():
'''
helper function to gain insight on provided data sets background,
using pylab
'''
data1 = [[1.0, 1], [2.25, 3.5], [3.58333333333, 7.5], [4.95833333333, 13.0], [6.35833333333, 20.0], [7.775, 28.5], [9.20357142857, 38.5], [10.6410714286, 50.0], [12.085515873, 63.0], [13.535515873, 77.5]]
data2 = [[1.0, 1], [1.75, 2.5], [2.41666666667, 4.5], [3.04166666667, 7.0], [3.64166666667, 10.0], [4.225, 13.5], [4.79642857143, 17.5], [5.35892857143, 22.0], [5.91448412698, 27.0], [6.46448412698, 32.5], [7.00993867244, 38.5], [7.55160533911, 45.0], [8.09006687757, 52.0], [8.62578116328, 59.5], [9.15911449661, 67.5], [9.69036449661, 76.0], [10.2197762613, 85.0], [10.7475540391, 94.5], [11.2738698286, 104.5], [11.7988698286, 115.0]]
time1 = [item[0] for item in data1]
resource1 = [item[1] for item in data1]
time2 = [item[0] for item in data2]
resource2 = [item[1] for item in data2]
# plot in pylab (total resources over time)
pylab.plot(time1, resource1, 'o')
pylab.plot(time2, resource2, 'o')
pylab.title('Silly Homework')
pylab.legend(('Data Set no.1', 'Data Set no.2'))
pylab.xlabel('Current Time')
pylab.ylabel('Total Resources Generated')
pylab.show()
#plot_it()
示例3: plot_question2
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_question2():
'''
graph of total resources generated as a function of time,
for four various upgrade_cost_increment values
'''
for upgrade_cost_increment in [0.0, 0.5, 1.0, 2.0]:
data = resources_vs_time(upgrade_cost_increment, 5)
time = [item[0] for item in data]
resource = [item[1] for item in data]
# plot in pylab (total resources over time for each constant)
pylab.plot(time, resource, 'o')
pylab.title('Silly Homework')
pylab.legend(('0.0', '0.5', '1.0', '2.0'))
pylab.xlabel('Current Time')
pylab.ylabel('Total Resources Generated')
pylab.show()
#plot_question2()
# Question 3
示例4: plot_question3
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_question3():
'''
graph of total resources generated as a function of time;
for upgrade_cost_increment == 0
'''
data = resources_vs_time(0.0, 100)
time = [item[0] for item in data]
resource = [item[1] for item in data]
# plot in pylab on logarithmic scale (total resources over time for upgrade growth 0.0)
pylab.loglog(time, resource)
pylab.title('Silly Homework')
pylab.legend('0.0')
pylab.xlabel('Current Time')
pylab.ylabel('Total Resources Generated')
pylab.show()
#plot_question3()
# Question 4
示例5: plot_question7
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_question7():
'''
graph of total resources generated as a function of time,
for upgrade_cost_increment == 1
'''
data = resources_vs_time(1.0, 50)
time = [item[0] for item in data]
resource = [item[1] for item in data]
a, b, c = pylab.polyfit(time, resource, 2)
print 'polyfit with argument \'2\' fits the data, thus the degree of the polynomial is 2 (quadratic)'
# plot in pylab on logarithmic scale (total resources over time for upgrade growth 0.0)
#pylab.loglog(time, resource, 'o')
# plot fitting function
yp = pylab.polyval([a, b, c], time)
pylab.plot(time, yp)
pylab.scatter(time, resource)
pylab.title('Silly Homework, Question 7')
pylab.legend(('Resources for increment 1', 'Fitting function' + ', slope: ' + str(a)))
pylab.xlabel('Current Time')
pylab.ylabel('Total Resources Generated')
pylab.grid()
pylab.show()
示例6: plot_entropy
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_entropy(self):
"""
Returns:
"""
try:
import pylab as plt
except ImportError:
import matplotlib.pyplot as plt
plt.plot(
self.temperatures,
self.eV_to_J_per_mol / self.num_atoms * self.get_entropy_p(),
label="S$_p$",
)
plt.plot(
self.temperatures,
self.eV_to_J_per_mol / self.num_atoms * self.get_entropy_v(),
label="S$_V$",
)
plt.legend()
plt.xlabel("Temperature [K]")
plt.ylabel("Entropy [J K$^{-1}$ mol-atoms$^{-1}$]")
示例7: plot_Geweke
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_Geweke(parameterdistribution,parametername):
'''Input: Takes a list of sampled values for a parameter and his name as a string
Output: Plot as seen for e.g. in BUGS or PyMC'''
import matplotlib.pyplot as plt
# perform the Geweke test
Geweke_values = _Geweke(parameterdistribution)
# plot the results
fig = plt.figure()
plt.plot(Geweke_values,label=parametername)
plt.legend()
plt.title(parametername + '- Geweke_Test')
plt.xlabel('Subinterval')
plt.ylabel('Geweke Test')
plt.ylim([-3,3])
# plot the delimiting line
plt.plot( [2]*len(Geweke_values), 'r-.')
plt.plot( [-2]*len(Geweke_values), 'r-.')
示例8: impose_legend_limit
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def impose_legend_limit(limit=30, axes="gca", **kwargs):
"""
This will erase all but, say, 30 of the legend entries and remake the legend.
You'll probably have to move it back into your favorite position at this point.
"""
if axes=="gca": axes = _pylab.gca()
# make these axes current
_pylab.axes(axes)
# loop over all the lines_pylab.
for n in range(0,len(axes.lines)):
if n > limit-1 and not n==len(axes.lines)-1: axes.lines[n].set_label("_nolegend_")
if n == limit-1 and not n==len(axes.lines)-1: axes.lines[n].set_label("...")
_pylab.legend(**kwargs)
示例9: _plotFMeasures
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def _plotFMeasures(fstepsize=.1, stepsize=0.0005, start = 0.0, end = 1.0):
"""Plots 10 fmeasure Curves into the current canvas."""
p = sc.arange(start, end, stepsize)[1:]
for f in sc.arange(0., 1., fstepsize)[1:]:
points = [(x, _fmeasureCurve(f, x)) for x in p
if 0 < _fmeasureCurve(f, x) <= 1.5]
try:
xs, ys = zip(*points)
curve, = pl.plot(xs, ys, "--", color="gray", linewidth=0.8) # , label=r"$f=%.1f$"%f) # exclude labels, for legend
# bad hack:
# gets the 10th last datapoint, from that goes a bit to the left, and a bit down
datapoint_x_loc = int(len(xs)/2)
datapoint_y_loc = int(len(ys)/2)
# x_left = 0.05
# y_left = 0.035
x_left = 0.035
y_left = -0.02
pl.annotate(r"$f=%.1f$" % f, xy=(xs[datapoint_x_loc], ys[datapoint_y_loc]), xytext=(xs[datapoint_x_loc] - x_left, ys[datapoint_y_loc] - y_left), size="small", color="gray")
except Exception as e:
print e
#colors = "gcmbbbrrryk"
#colors = "yyybbbrrrckgm" # 7 is a prime, so we'll loop over all combinations of colors and markers, when zipping their cycles
示例10: main
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def main():
l2_base_dir = '/media/admin228/00027E210001A5BD/train_pytorch/change_detection/CMU/prediction_cons/l2_5,6,7/roc'
cos_base_dir = '/media/admin228/00027E210001A5BD/train_pytorch/change_detection/CMU/prediction_cons/dist_cos_new_5,6,7/roc'
CSF_dir = os.path.join(l2_base_dir)
CSF_fig_dir = os.path.join(l2_base_dir,'fig.png')
end_number = 22
csf_conv5_l2_ls,csf_fc6_l2_ls,csf_fc7_l2_ls,x_l2 = get_csf_ls(l2_base_dir,end_number)
csf_conv5_cos_ls,csf_fc6_cos_ls,csf_fc7_cos_ls,x_cos = get_csf_ls(cos_base_dir,end_number)
Fig = pylab.figure()
setFigLinesBW(Fig)
#pylab.plot(x,csf_conv4_ls, color='k',label= 'conv4')
pylab.plot(x_l2,csf_conv5_l2_ls, color='m',label= 'l2:conv5')
pylab.plot(x_l2,csf_fc6_l2_ls, color = 'b',label= 'l2:fc6')
pylab.plot(x_l2,csf_fc7_l2_ls, color = 'g',label= 'l2:fc7')
pylab.plot(x_cos,csf_conv5_cos_ls, color='c',label= 'cos:conv5')
pylab.plot(x_cos,csf_fc6_cos_ls, color = 'r',label= 'cos:fc6')
pylab.plot(x_cos,csf_fc7_cos_ls, color = 'y',label= 'cos:fc7')
pylab.legend(loc='lower right', prop={'size': 10})
pylab.ylabel('RMS Contrast', fontsize=14)
pylab.xlabel('Epoch', fontsize=14)
pylab.savefig(CSF_fig_dir)
示例11: plot_sensor_data
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_sensor_data(self, title, timestamp, x, y, z):
if not self.to_save and not self.to_show:
return
self.big_figure()
pylab.grid("on")
pylab.plot(timestamp, x, color='r', label='x')
pylab.plot(timestamp, y, color='g', label='y')
pylab.plot(timestamp, z, color='b', label='z')
pylab.legend()
pylab.title(title)
pylab.xlabel('Time')
pylab.ylabel('Amplitude')
示例12: plot_data
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_data(self, title, data, xlabel, ylabel, colors=None, labels=None):
if not self.to_save and not self.to_show:
return
self.big_figure()
for i in range(0, len(data)):
color = 'm' if colors is None else colors[i]
if labels is None:
pylab.plot(data[i], color=color)
else:
pylab.plot(data[i], color=color, label=labels[i])
if labels is not None:
pylab.legend()
pylab.title(title)
pylab.xlabel(xlabel)
pylab.ylabel(ylabel)
示例13: plot_signal_and_label
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_signal_and_label(self, title, timestamp, signal, label_timestamp, label):
if not self.to_save and not self.to_show:
return
pylab.figure()
pylab.plot(timestamp, signal, color='m', label='signal')
for i in range(0, len(label_timestamp)):
pylab.axvline(label_timestamp[i], color="k", label="{}: key {}".format(i, label[i]), ls='dashed')
pylab.legend()
pylab.title(title)
pylab.xlabel('Time')
pylab.ylabel('Amplitude')
示例14: plot_barchart
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def plot_barchart(self, data, labels, colors, xlabel, ylabel, xticks, legendloc=1):
self.big_figure()
index = np.arange(len(data[0][0]))
bar_width = 0.25
pylab.grid("on", axis='y')
pylab.ylim([0.5, 1.0])
for i in range(0, len(data)):
rects = pylab.bar(bar_width / 2 + index + (i * bar_width), data[i][0], bar_width,
alpha=0.5, color=colors[i],
yerr=data[i][1],
error_kw={'ecolor': '0.3'},
label=labels[i])
pylab.legend(loc=legendloc, prop={'size': 12})
pylab.xlabel(xlabel)
pylab.ylabel(ylabel)
pylab.xticks(bar_width / 2 + index + ((bar_width * (len(data[0]) + 1)) / len(data[0])), xticks)
示例15: addqqplotinfo
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import legend [as 別名]
def addqqplotinfo(qnull,M,xl='-log10(P) observed',yl='-log10(P) expected',xlim=None,ylim=None,alphalevel=0.05,legendlist=None,fixaxes=False):
distr='log10'
pl.plot([0,qnull.max()], [0,qnull.max()],'k')
pl.ylabel(xl)
pl.xlabel(yl)
if xlim is not None:
pl.xlim(xlim)
if ylim is not None:
pl.ylim(ylim)
if alphalevel is not None:
if distr == 'log10':
betaUp, betaDown, theoreticalPvals = _qqplot_bar(M=M,alphalevel=alphalevel,distr=distr)
lower = -sp.log10(theoreticalPvals-betaDown)
upper = -sp.log10(theoreticalPvals+betaUp)
pl.fill_between(-sp.log10(theoreticalPvals),lower,upper,color="grey",alpha=0.5)
#pl.plot(-sp.log10(theoreticalPvals),lower,'g-.')
#pl.plot(-sp.log10(theoreticalPvals),upper,'g-.')
if legendlist is not None:
leg = pl.legend(legendlist, loc=4, numpoints=1)
# set the markersize for the legend
for lo in leg.legendHandles:
lo.set_markersize(10)
if fixaxes:
fix_axes()