本文整理汇总了Python中matplotlib.pylab.annotate方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.annotate方法的具体用法?Python pylab.annotate怎么用?Python pylab.annotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.annotate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import annotate [as 别名]
def plot(self, words, num_points=None):
if not num_points:
num_points = len(words)
embeddings = self.get_words_embeddings(words)
tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
two_d_embeddings = tsne.fit_transform(embeddings[:num_points, :])
assert two_d_embeddings.shape[0] >= len(words), 'More labels than embeddings'
pylab.figure(figsize=(15, 15)) # in inches
for i, label in enumerate(words[:num_points]):
x, y = two_d_embeddings[i, :]
pylab.scatter(x, y)
pylab.annotate(label, xy=(x, y), xytext=(5, 2), textcoords='offset points',
ha='right', va='bottom')
pylab.show()
示例2: plot_stocks
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import annotate [as 别名]
def plot_stocks(self, freq=252):
"""Plots the Expected annual Returns over annual Volatility of
the stocks of the portfolio.
:Input:
:freq: ``int`` (default: ``252``), number of trading days, default
value corresponds to trading days in a year.
"""
# annual mean returns of all stocks
stock_returns = self.comp_mean_returns(freq=freq)
stock_volatility = self.comp_stock_volatility(freq=freq)
# adding stocks of the portfolio to the plot
# plot stocks individually:
plt.scatter(stock_volatility, stock_returns, marker="o", s=100, label="Stocks")
# adding text to stocks in plot:
for i, txt in enumerate(stock_returns.index):
plt.annotate(
txt,
(stock_volatility[i], stock_returns[i]),
xytext=(10, 0),
textcoords="offset points",
label=i,
)
plt.legend()
示例3: plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import annotate [as 别名]
def plot(embeddings, labels):
assert embeddings.shape[0] >= len(labels), 'More labels than embeddings'
pylab.figure(figsize=(15,15)) # in inches
for i, label in enumerate(labels):
x, y = embeddings[i,:]
pylab.scatter(x, y)
pylab.annotate(label, xy=(x, y), xytext=(5, 2), textcoords='offset points',
ha='right', va='bottom')
pylab.show()
示例4: plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import annotate [as 别名]
def plot(embeddings, labels):
assert embeddings.shape[0] >= len(labels), 'More labels than embeddings'
pylab.figure(figsize=(15, 15)) # in inches
for i, label in enumerate(labels):
x, y = embeddings[i, :]
pylab.scatter(x, y)
pylab.annotate(label, xy=(x, y), xytext=(5, 2), textcoords='offset points',
ha='right', va='bottom')
pylab.show()