本文整理汇总了Python中matplotlib.pylab.hist方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.hist方法的具体用法?Python pylab.hist怎么用?Python pylab.hist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.hist方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compute_class_prior
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def compute_class_prior(do_plot=False):
categories_folder = 'data/instance-level_human_parsing/Training/Category_ids'
names = [f for f in os.listdir(categories_folder) if f.lower().endswith('.png')]
num_samples = len(names)
prior_prob = np.zeros(num_classes)
pb = ProgressBar(total=num_samples, prefix='Compute class prior', suffix='', decimals=3, length=50, fill='=')
for i in range(num_samples):
name = names[i]
filename = os.path.join(categories_folder, name)
category = np.ravel(cv.imread(filename, 0))
counts = np.bincount(category)
idxs = np.nonzero(counts)[0]
prior_prob[idxs] += counts[idxs]
pb.print_progress_bar(i + 1)
prior_prob = prior_prob / (1.0 * np.sum(prior_prob))
# Save
np.save(os.path.join(data_dir, "prior_prob.npy"), prior_prob)
if do_plot:
plt.hist(prior_prob, bins=100)
plt.yscale("log")
plt.show()
示例2: plotkde
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def plotkde(covfact):
gkde.reset_covfact(covfact)
kdepdf = gkde.evaluate(ind)
plt.figure()
# plot histgram of sample
plt.hist(xn, bins=20, normed=1)
# plot estimated density
plt.plot(ind, kdepdf, label='kde', color="g")
# plot data generating density
plt.plot(ind, alpha * stats.norm.pdf(ind, loc=mlow) +
(1-alpha) * stats.norm.pdf(ind, loc=mhigh),
color="r", label='DGP: normal mix')
plt.title('Kernel Density Estimation - ' + str(gkde.covfact))
plt.legend()
示例3: plot_feat_hist
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def plot_feat_hist(data_name_list, filename=None):
pylab.clf()
num_rows = 1 + (len(data_name_list) - 1) / 2
num_cols = 1 if len(data_name_list) == 1 else 2
pylab.figure(figsize=(5 * num_cols, 4 * num_rows))
for i in range(num_rows):
for j in range(num_cols):
pylab.subplot(num_rows, num_cols, 1 + i * num_cols + j)
x, name = data_name_list[i * num_cols + j]
pylab.title(name)
pylab.xlabel('Value')
pylab.ylabel('Density')
# the histogram of the data
max_val = np.max(x)
if max_val <= 1.0:
bins = 50
elif max_val > 50:
bins = 50
else:
bins = max_val
n, bins, patches = pylab.hist(
x, bins=bins, normed=1, facecolor='green', alpha=0.75)
pylab.grid(True)
if not filename:
filename = "feat_hist_%s.png" % name
pylab.savefig(os.path.join(CHART_DIR, filename), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:32,代码来源:utils.py
示例4: plot_feat_hist
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def plot_feat_hist(data_name_list, filename=None):
if len(data_name_list) > 1:
assert filename is not None
pylab.figure(num=None, figsize=(8, 6))
num_rows = int(1 + (len(data_name_list) - 1) / 2)
num_cols = int(1 if len(data_name_list) == 1 else 2)
pylab.figure(figsize=(5 * num_cols, 4 * num_rows))
for i in range(num_rows):
for j in range(num_cols):
pylab.subplot(num_rows, num_cols, 1 + i * num_cols + j)
x, name = data_name_list[i * num_cols + j]
pylab.title(name)
pylab.xlabel('Value')
pylab.ylabel('Fraction')
# the histogram of the data
max_val = np.max(x)
if max_val <= 1.0:
bins = 50
elif max_val > 50:
bins = 50
else:
bins = max_val
n, bins, patches = pylab.hist(
x, bins=bins, normed=1, alpha=0.75)
pylab.grid(True)
if not filename:
filename = "feat_hist_%s.png" % name.replace(" ", "_")
pylab.savefig(os.path.join(CHART_DIR, filename), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:35,代码来源:utils.py
示例5: plotkde
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def plotkde(covfact):
gkde.reset_covfact(covfact)
kdepdf = gkde.evaluate(ind)
plt.figure()
# plot histgram of sample
plt.hist(xn, bins=20, normed=1)
# plot estimated density
plt.plot(ind, kdepdf, label='kde', color="g")
# plot data generating density
plt.plot(ind, alpha * stats.norm.pdf(ind, loc=mlow) +
(1-alpha) * stats.norm.pdf(ind, loc=mhigh),
color="r", label='DGP: normal mix')
plt.title('Kernel Density Estimation - ' + str(gkde.covfact))
plt.legend()
示例6: histogram
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def histogram(vals, variable, n, outFile):
figFile = os.path.splitext(outFile)[0] + '_hist.png'
M.clf()
# M.hist(vals, 47, (-2., 45.))
M.hist(vals, 94)
M.xlim(-5, 45)
M.xlabel('SST in degrees Celsius')
M.ylim(0, 300000)
M.ylabel('Count')
M.title('Histogram of %s %d-day Mean from %s' % (variable.upper(), n, outFile))
M.show()
print >> sys.stderr, 'Writing histogram plot to %s' % figFile
M.savefig(figFile)
return figFile
示例7: hist
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def hist(x, bins, outFile=None, **options):
if outFile: M.clf()
M.hist(x, bins, **options)
if outFile: M.savefig(outFile, **validCmdOptions(options, 'savefig'))
示例8: histogram
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def histogram(vals, variable, n, outFile):
figFile = os.path.splitext(outFile)[0] + '_hist.png'
M.clf()
# M.hist(vals, 47, (-2., 45.))
M.hist(vals, 94)
M.xlim(-5, 45)
M.xlabel('SST in degrees Celsius')
M.ylim(0, 300000)
M.ylabel('Count')
M.title('Histogram of %s %d-day Mean from %s' % (variable.upper(), n, outFile))
M.show()
print >>sys.stderr, 'Writing histogram plot to %s' % figFile
M.savefig(figFile)
return figFile
示例9: plot_null_distribution
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def plot_null_distribution(stats, stats_null, p_value, data_name='',
stats_name='$MMD^2_u$', save_figure=True):
"""Plot the observed value for the test statistic, its null
distribution and p-value.
"""
fig = plt.figure()
ax = fig.add_subplot(111)
prob, bins, patches = plt.hist(stats_null, bins=50, normed=True)
ax.plot(stats, prob.max()/30, 'w*', markersize=15,
markeredgecolor='k', markeredgewidth=2,
label="%s = %s" % (stats_name, stats))
ax.annotate('p-value: %s' % (p_value),
xy=(float(stats), prob.max()/9.), xycoords='data',
xytext=(-105, 30), textcoords='offset points',
bbox=dict(boxstyle="round", fc="1."),
arrowprops={"arrowstyle": "->",
"connectionstyle": "angle,angleA=0,angleB=90,rad=10"},
)
plt.xlabel(stats_name)
plt.ylabel('p(%s)' % stats_name)
plt.legend(numpoints=1)
plt.title('Data: %s' % data_name)
if save_figure:
save_dir = 'figures'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
stn = 'ktst' if stats_name == '$MMD^2_u$' else 'clf'
fig_name = os.path.join(save_dir, '%s_%s.pdf' % (data_name, stn))
fig.savefig(fig_name)
示例10: compute_color_prior
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import hist [as 别名]
def compute_color_prior(size=64, do_plot=False):
# Load the gamut points location
q_ab = np.load(os.path.join(data_dir, "pts_in_hull.npy"))
if do_plot:
plt.figure(figsize=(15, 15))
gs = gridspec.GridSpec(1, 1)
ax = plt.subplot(gs[0])
for i in range(q_ab.shape[0]):
ax.scatter(q_ab[:, 0], q_ab[:, 1])
ax.annotate(str(i), (q_ab[i, 0], q_ab[i, 1]), fontsize=6)
ax.set_xlim([-110,110])
ax.set_ylim([-110,110])
with h5py.File(os.path.join(data_dir, "CelebA_%s_data.h5" % size), "a") as hf:
# Compute the color prior over a subset of the training set
# Otherwise it is quite long
X_ab = hf["training_lab_data"][:100000][:, 1:, :, :]
npts, c, h, w = X_ab.shape
X_a = np.ravel(X_ab[:, 0, :, :])
X_b = np.ravel(X_ab[:, 1, :, :])
X_ab = np.vstack((X_a, X_b)).T
if do_plot:
plt.hist2d(X_ab[:, 0], X_ab[:, 1], bins=100, norm=LogNorm())
plt.xlim([-110, 110])
plt.ylim([-110, 110])
plt.colorbar()
plt.show()
plt.clf()
plt.close()
# Create nearest neighbord instance with index = q_ab
NN = 1
nearest = nn.NearestNeighbors(n_neighbors=NN, algorithm='ball_tree').fit(q_ab)
# Find index of nearest neighbor for X_ab
dists, ind = nearest.kneighbors(X_ab)
# We now count the number of occurrences of each color
ind = np.ravel(ind)
counts = np.bincount(ind)
idxs = np.nonzero(counts)[0]
prior_prob = np.zeros((q_ab.shape[0]))
for i in range(q_ab.shape[0]):
prior_prob[idxs] = counts[idxs]
# We turn this into a color probability
prior_prob = prior_prob / (1.0 * np.sum(prior_prob))
# Save
np.save(os.path.join(data_dir, "CelebA_%s_prior_prob.npy" % size), prior_prob)
if do_plot:
plt.hist(prior_prob, bins=100)
plt.yscale("log")
plt.show()