本文整理汇总了Python中matplotlib.pylab.yticks方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.yticks方法的具体用法?Python pylab.yticks怎么用?Python pylab.yticks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.yticks方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_pr_curve
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def plot_pr_curve(pr_curve_dml, pr_curve_base, title):
"""
Function that plots the PR-curve.
Args:
pr_curve: the values of precision for each recall value
title: the title of the plot
"""
plt.figure(figsize=(16, 9))
plt.plot(np.arange(0.0, 1.05, 0.05),
pr_curve_base, color='r', marker='o', linewidth=3, markersize=10)
plt.plot(np.arange(0.0, 1.05, 0.05),
pr_curve_dml, color='b', marker='o', linewidth=3, markersize=10)
plt.grid(True, linestyle='dotted')
plt.xlabel('Recall', color='k', fontsize=27)
plt.ylabel('Precision', color='k', fontsize=27)
plt.yticks(color='k', fontsize=20)
plt.xticks(color='k', fontsize=20)
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
plt.title(title, color='k', fontsize=27)
plt.tight_layout()
plt.show()
示例2: dispersion_plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def dispersion_plot(text, words, ignore_case=False, title="Lexical Dispersion Plot"):
"""
Generate a lexical dispersion plot.
:param text: The source text
:type text: list(str) or enum(str)
:param words: The target words
:type words: list of str
:param ignore_case: flag to set if case should be ignored when searching text
:type ignore_case: bool
"""
try:
from matplotlib import pylab
except ImportError:
raise ValueError('The plot function requires matplotlib to be installed.'
'See http://matplotlib.org/')
text = list(text)
words.reverse()
if ignore_case:
words_to_comp = list(map(str.lower, words))
text_to_comp = list(map(str.lower, text))
else:
words_to_comp = words
text_to_comp = text
points = [(x,y) for x in range(len(text_to_comp))
for y in range(len(words_to_comp))
if text_to_comp[x] == words_to_comp[y]]
if points:
x, y = list(zip(*points))
else:
x = y = ()
pylab.plot(x, y, "b|", scalex=.1)
pylab.yticks(list(range(len(words))), words, color="b")
pylab.ylim(-1, len(words))
pylab.title(title)
pylab.xlabel("Word Offset")
pylab.show()
示例3: malt_demo
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def malt_demo(nx=False):
"""
A demonstration of the result of reading a dependency
version of the first sentence of the Penn Treebank.
"""
dg = DependencyGraph("""Pierre NNP 2 NMOD
Vinken NNP 8 SUB
, , 2 P
61 CD 5 NMOD
years NNS 6 AMOD
old JJ 2 NMOD
, , 2 P
will MD 0 ROOT
join VB 8 VC
the DT 11 NMOD
board NN 9 OBJ
as IN 9 VMOD
a DT 15 NMOD
nonexecutive JJ 15 NMOD
director NN 12 PMOD
Nov. NNP 9 VMOD
29 CD 16 NMOD
. . 9 VMOD
""")
tree = dg.tree()
tree.pprint()
if nx:
# currently doesn't work
import networkx
from matplotlib import pylab
g = dg.nx_graph()
g.info()
pos = networkx.spring_layout(g, dim=1)
networkx.draw_networkx_nodes(g, pos, node_size=50)
# networkx.draw_networkx_edges(g, pos, edge_color='k', width=8)
networkx.draw_networkx_labels(g, pos, dg.nx_labels)
pylab.xticks([])
pylab.yticks([])
pylab.savefig('tree.png')
pylab.show()
示例4: imshow_
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def imshow_(x, **kwargs):
if x.ndim == 2:
plt.imshow(x, interpolation="nearest", **kwargs)
elif x.ndim == 1:
plt.imshow(x[:, None].T, interpolation="nearest", **kwargs)
plt.yticks([])
plt.axis("tight")
# ------------- Data -------------
示例5: plot1D_mat
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def plot1D_mat(a, b, M, title=''):
""" Plot matrix M with the source and target 1D distribution
Creates a subplot with the source distribution a on the left and
target distribution b on the tot. The matrix M is shown in between.
Parameters
----------
a : ndarray, shape (na,)
Source distribution
b : ndarray, shape (nb,)
Target distribution
M : ndarray, shape (na, nb)
Matrix to plot
"""
na, nb = M.shape
gs = gridspec.GridSpec(3, 3)
xa = np.arange(na)
xb = np.arange(nb)
ax1 = pl.subplot(gs[0, 1:])
pl.plot(xb, b, 'r', label='Target distribution')
pl.yticks(())
pl.title(title)
ax2 = pl.subplot(gs[1:, 0])
pl.plot(a, xa, 'b', label='Source distribution')
pl.gca().invert_xaxis()
pl.gca().invert_yaxis()
pl.xticks(())
pl.subplot(gs[1:, 1:], sharex=ax1, sharey=ax2)
pl.imshow(M, interpolation='nearest')
pl.axis('off')
pl.xlim((0, nb))
pl.tight_layout()
pl.subplots_adjust(wspace=0., hspace=0.2)
示例6: imshow_
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def imshow_(x, **kwargs):
if x.ndim == 2:
plt.imshow(x, interpolation="nearest", **kwargs)
elif x.ndim == 1:
plt.imshow(x[:,None].T, interpolation="nearest", **kwargs)
plt.yticks([])
plt.axis("tight")
# ------------- Data -------------
示例7: plot_confusion_matrix
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def plot_confusion_matrix(y_true, y_pred, classes, figure_size=(8, 8)):
"""This function plots a confusion matrix."""
# Compute confusion matrix
cm = confusion_matrix(y_true, y_pred)
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] * 100
# Build Laussen Labs colormap
cmap = LinearSegmentedColormap.from_list('laussen_labs_green', ['w', '#43BB9B'], N=256)
# Setup plot
plt.figure(figsize=figure_size)
# Plot confusion matrix
plt.imshow(cm, interpolation='nearest', cmap=cmap)
# Modify axes
tick_marks = np.arange(len(classes))
plt.xticks(tick_marks, classes, rotation=90)
plt.yticks(tick_marks, classes)
thresh = cm.max() / 1.5
for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
plt.text(j, i, str(np.round(cm[i, j], 2)) + ' %', horizontalalignment="center",
color="white" if cm[i, j] > thresh else "black", fontsize=20)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.tight_layout()
plt.ylabel('True Label', fontsize=25)
plt.xlabel('Predicted Label', fontsize=25)
plt.show()
示例8: interval_plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def interval_plot(label_id, labels, path, dataset):
"""Plot measure vs time."""
# Label lookup
label_lookup = {0: 'N', 1: 'A', 2: 'O', 3: '~'}
# File name
file_name = list(labels.keys())[label_id]
# Get label
label = labels[file_name]
# Load data
data = np.load(os.path.join(path, dataset, 'waveforms', file_name + '.npy'))
# Time array
time = np.arange(data.shape[0]) * 1 / 300
# Setup figure
fig = plt.figure(figsize=(15, 5), facecolor='w')
fig.subplots_adjust(wspace=0, hspace=0.05)
ax1 = plt.subplot2grid((1, 1), (0, 0))
# ECG
ax1.set_title('Dataset: {}\nFile Name: {}\nLabel: {}'.format(dataset, file_name, label_lookup[label]), fontsize=20)
ax1.plot(time, data, '-k', lw=2)
# Axes labels
ax1.set_xlabel('Time, seconds', fontsize=20)
ax1.set_ylabel('ECG', fontsize=20)
ax1.set_xlim([time.min(), time.max()])
plt.yticks(fontsize=12)
plt.show()
示例9: plotCovMatFromHModel
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def plotCovMatFromHModel(hmodel, compListToPlot=None, compsToHighlight=None, wTHR=0.001):
''' Plot cov matrix visualization for each "significant" component in hmodel
Args
-------
hmodel : bnpy HModel object
compListToPlot : array-like of integer IDs of components within hmodel
compsToHighlight : int or array-like of integer IDs to highlight
if None, all components get unique colors
if not None, only highlighted components get colors.
wTHR : float threshold on minimum weight assigned to comp tobe "plottable"
'''
if compsToHighlight is not None:
compsToHighlight = np.asarray(compsToHighlight)
if compsToHighlight.ndim == 0:
compsToHighlight = np.asarray([compsToHighlight])
else:
compsToHighlight = list()
if compListToPlot is None:
compListToPlot = np.arange(0, hmodel.allocModel.K)
try:
w = np.exp(hmodel.allocModel.Elogw)
except Exception:
w = hmodel.allocModel.w
nRow = 2
nCol = np.ceil(hmodel.obsModel.K/2.0)
colorID = 0
for plotID, kk in enumerate(compListToPlot):
if w[kk] < wTHR and kk not in compsToHighlight:
Sigma = getEmptyCompSigmaImage(hmodel.obsModel.D)
clim = [0, 1]
else:
Sigma = hmodel.obsModel.get_covar_mat_for_comp(kk)
clim = [-.25, 1]
pylab.subplot(nRow, nCol, plotID)
pylab.imshow(Sigma, interpolation='nearest', cmap='hot', clim=clim)
pylab.xticks([])
pylab.yticks([])
pylab.xlabel('%.2f' % (w[kk]))
if kk in compsToHighlight:
pylab.xlabel('***')
示例10: plotBarsFromHModel
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def plotBarsFromHModel(hmodel, Data=None, doShowNow=True, figH=None,
compsToHighlight=None, sortBySize=False,
width=12, height=3, Ktop=None):
if Data is None:
width = width/2
if figH is None:
figH = pylab.figure(figsize=(width,height))
else:
pylab.axes(figH)
K = hmodel.allocModel.K
VocabSize = hmodel.obsModel.comp[0].lamvec.size
learned_tw = np.zeros( (K, VocabSize) )
for k in xrange(K):
lamvec = hmodel.obsModel.comp[k].lamvec
learned_tw[k,:] = lamvec / lamvec.sum()
if sortBySize:
sortIDs = np.argsort(hmodel.allocModel.Ebeta[:-1])[::-1]
sortIDs = sortIDs[:Ktop]
learned_tw = learned_tw[sortIDs]
if Data is not None and hasattr(Data, "true_tw"):
# Plot the true parameters and learned parameters
pylab.subplot(121)
pylab.imshow(Data.true_tw, **imshowArgs)
pylab.colorbar()
pylab.title('True Topic x Word')
pylab.subplot(122)
pylab.imshow(learned_tw, **imshowArgs)
pylab.title('Learned Topic x Word')
else:
# Plot just the learned parameters
aspectR = learned_tw.shape[1]/learned_tw.shape[0]
while imshowArgs['vmax'] > 2 * np.percentile(learned_tw, 97):
imshowArgs['vmax'] /= 5
pylab.imshow(learned_tw, aspect=aspectR, **imshowArgs)
if compsToHighlight is not None:
ks = np.asarray(compsToHighlight)
if ks.ndim == 0:
ks = np.asarray([ks])
pylab.yticks( ks, ['**** %d' % (k) for k in ks])
if doShowNow and figH is None:
pylab.show()
示例11: dispersion_plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def dispersion_plot(text, words, ignore_case=False, title="Lexical Dispersion Plot"):
"""
Generate a lexical dispersion plot.
:param text: The source text
:type text: list(str) or enum(str)
:param words: The target words
:type words: list of str
:param ignore_case: flag to set if case should be ignored when searching text
:type ignore_case: bool
"""
try:
from matplotlib import pylab
except ImportError:
raise ValueError(
'The plot function requires matplotlib to be installed.'
'See http://matplotlib.org/'
)
text = list(text)
words.reverse()
if ignore_case:
words_to_comp = list(map(str.lower, words))
text_to_comp = list(map(str.lower, text))
else:
words_to_comp = words
text_to_comp = text
points = [
(x, y)
for x in range(len(text_to_comp))
for y in range(len(words_to_comp))
if text_to_comp[x] == words_to_comp[y]
]
if points:
x, y = list(zip(*points))
else:
x = y = ()
pylab.plot(x, y, "b|", scalex=0.1)
pylab.yticks(list(range(len(words))), words, color="b")
pylab.ylim(-1, len(words))
pylab.title(title)
pylab.xlabel("Word Offset")
pylab.show()
示例12: malt_demo
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import yticks [as 别名]
def malt_demo(nx=False):
"""
A demonstration of the result of reading a dependency
version of the first sentence of the Penn Treebank.
"""
dg = DependencyGraph(
"""Pierre NNP 2 NMOD
Vinken NNP 8 SUB
, , 2 P
61 CD 5 NMOD
years NNS 6 AMOD
old JJ 2 NMOD
, , 2 P
will MD 0 ROOT
join VB 8 VC
the DT 11 NMOD
board NN 9 OBJ
as IN 9 VMOD
a DT 15 NMOD
nonexecutive JJ 15 NMOD
director NN 12 PMOD
Nov. NNP 9 VMOD
29 CD 16 NMOD
. . 9 VMOD
"""
)
tree = dg.tree()
tree.pprint()
if nx:
# currently doesn't work
import networkx
from matplotlib import pylab
g = dg.nx_graph()
g.info()
pos = networkx.spring_layout(g, dim=1)
networkx.draw_networkx_nodes(g, pos, node_size=50)
# networkx.draw_networkx_edges(g, pos, edge_color='k', width=8)
networkx.draw_networkx_labels(g, pos, dg.nx_labels)
pylab.xticks([])
pylab.yticks([])
pylab.savefig('tree.png')
pylab.show()