本文整理汇总了Python中pylab.annotate方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.annotate方法的具体用法?Python pylab.annotate怎么用?Python pylab.annotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylab
的用法示例。
在下文中一共展示了pylab.annotate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _plotFMeasures
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import annotate [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
示例2: plot_confusion_matrix
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import annotate [as 别名]
def plot_confusion_matrix(self, matrix, labels):
if not self.to_save and not self.to_show:
return
pylab.figure()
pylab.imshow(matrix, interpolation='nearest', cmap=pylab.cm.jet)
pylab.title("Confusion Matrix")
for i, vi in enumerate(matrix):
for j, vj in enumerate(vi):
pylab.annotate("%.1f" % vj, xy=(j, i), horizontalalignment='center', verticalalignment='center', fontsize=9)
pylab.colorbar()
classes = np.arange(len(labels))
pylab.xticks(classes, labels)
pylab.yticks(classes, labels)
pylab.ylabel('Expected label')
pylab.xlabel('Predicted label')
示例3: add_annotation
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import annotate [as 别名]
def add_annotation(ax, text, x, y, z=None):
from mpl_toolkits.mplot3d import proj3d
import pylab
if not z is None:
x2, y2, _ = proj3d.proj_transform(x,y,z, ax.get_proj())
else:
x2, y2 = x, y
pylab.annotate(
text, xy = (x2, y2), xytext = (-20, 20),
textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
示例4: embed
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import annotate [as 别名]
def embed(words, matrix, classes, usermodel, fname):
perplexity = int(len(words) ** 0.5) # We set perplexity to a square root of the words number
embedding = TSNE(n_components=2, perplexity=perplexity, metric='cosine', n_iter=500, init='pca')
y = embedding.fit_transform(matrix)
print('2-d embedding finished', file=sys.stderr)
class_set = [c for c in set(classes)]
colors = plot.cm.rainbow(np.linspace(0, 1, len(class_set)))
class2color = [colors[class_set.index(w)] for w in classes]
xpositions = y[:, 0]
ypositions = y[:, 1]
seen = set()
plot.clf()
for color, word, class_label, x, y in zip(class2color, words, classes, xpositions, ypositions):
plot.scatter(x, y, 20, marker='.', color=color,
label=class_label if class_label not in seen else "")
seen.add(class_label)
lemma = word.split('_')[0].replace('::', ' ')
mid = len(lemma) / 2
mid *= 4 # TODO Should really think about how to adapt this variable to the real plot size
plot.annotate(lemma, xy=(x - mid, y), size='x-large', weight='bold', fontproperties=font,
color=color)
plot.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False)
plot.tick_params(axis='y', which='both', left=False, right=False, labelleft=False)
plot.legend(loc='best')
plot.savefig(root + 'data/images/tsneplots/' + usermodel + '_' + fname + '.png', dpi=150,
bbox_inches='tight')
plot.close()
plot.clf()
示例5: plot_embedding
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import annotate [as 别名]
def plot_embedding(data_matrix, y,
labels=None,
image_file_name=None,
title=None,
cmap='rainbow',
density=False):
"""plot_embedding."""
import matplotlib.pyplot as plt
from matplotlib import offsetbox
from PIL import Image
from eden.embedding import embed_dat_matrix_two_dimensions
if title is not None:
plt.title(title)
if density:
embed_dat_matrix_two_dimensions(data_matrix,
y=y,
instance_colormap=cmap)
else:
plt.scatter(data_matrix[:, 0], data_matrix[:, 1],
c=y,
cmap=cmap,
alpha=.7,
s=30,
edgecolors='black')
plt.xticks([])
plt.yticks([])
plt.axis('off')
if image_file_name is not None:
num_instances = data_matrix.shape[0]
ax = plt.subplot(111)
for i in range(num_instances):
img = Image.open(image_file_name + str(i) + '.png')
imagebox = offsetbox.AnnotationBbox(
offsetbox.OffsetImage(img, zoom=1),
data_matrix[i],
pad=0,
frameon=False)
ax.add_artist(imagebox)
if labels is not None:
for id in range(data_matrix.shape[0]):
label = str(labels[id])
x = data_matrix[id, 0]
y = data_matrix[id, 1]
plt.annotate(label,
xy=(x, y),
xytext=(0, 0),
textcoords='offset points')