本文整理汇总了Python中matplotlib.pylab.clf方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.clf方法的具体用法?Python pylab.clf怎么用?Python pylab.clf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.clf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_feat_importance
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def plot_feat_importance(feature_names, clf, name):
pylab.clf()
coef_ = clf.coef_
important = np.argsort(np.absolute(coef_.ravel()))
f_imp = feature_names[important]
coef = coef_.ravel()[important]
inds = np.argsort(coef)
f_imp = f_imp[inds]
coef = coef[inds]
xpos = np.array(range(len(coef)))
pylab.bar(xpos, coef, width=1)
pylab.title('Feature importance for %s' % (name))
ax = pylab.gca()
ax.set_xticks(np.arange(len(coef)))
labels = ax.set_xticklabels(f_imp)
for label in labels:
label.set_rotation(90)
filename = name.replace(" ", "_")
pylab.savefig(os.path.join(
CHART_DIR, "feat_imp_%s.png" % filename), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:23,代码来源:utils.py
示例2: plot_entropy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def plot_entropy():
pylab.clf()
pylab.figure(num=None, figsize=(5, 4))
title = "Entropy $H(X)$"
pylab.title(title)
pylab.xlabel("$P(X=$coin will show heads up$)$")
pylab.ylabel("$H(X)$")
pylab.xlim(xmin=0, xmax=1.1)
x = np.arange(0.001, 1, 0.001)
y = -x * np.log2(x) - (1 - x) * np.log2(1 - x)
pylab.plot(x, y)
# pylab.xticks([w*7*24 for w in [0,1,2,3,4]], ['week %i'%(w+1) for w in
# [0,1,2,3,4]])
pylab.autoscale(tight=True)
pylab.grid(True)
filename = "entropy_demo.png"
pylab.savefig(os.path.join(CHART_DIR, filename), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:23,代码来源:demo_mi.py
示例3: plot_confusion_matrix
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def plot_confusion_matrix(cm, genre_list, name, title):
pylab.clf()
pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=1.0)
ax = pylab.axes()
ax.set_xticks(range(len(genre_list)))
ax.set_xticklabels(genre_list)
ax.xaxis.set_ticks_position("bottom")
ax.set_yticks(range(len(genre_list)))
ax.set_yticklabels(genre_list)
pylab.title(title)
pylab.colorbar()
pylab.grid(False)
pylab.show()
pylab.xlabel('Predicted class')
pylab.ylabel('True class')
pylab.grid(False)
pylab.savefig(
os.path.join(CHART_DIR, "confusion_matrix_%s.png" % name), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:20,代码来源:utils.py
示例4: plot_roc
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def plot_roc(auc_score, name, tpr, fpr, label=None):
pylab.clf()
pylab.figure(num=None, figsize=(5, 4))
pylab.grid(True)
pylab.plot([0, 1], [0, 1], 'k--')
pylab.plot(fpr, tpr)
pylab.fill_between(fpr, tpr, alpha=0.5)
pylab.xlim([0.0, 1.0])
pylab.ylim([0.0, 1.0])
pylab.xlabel('False Positive Rate')
pylab.ylabel('True Positive Rate')
pylab.title('ROC curve (AUC = %0.2f) / %s' %
(auc_score, label), verticalalignment="bottom")
pylab.legend(loc="lower right")
filename = name.replace(" ", "_")
pylab.savefig(
os.path.join(CHART_DIR, "roc_" + filename + ".png"), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:19,代码来源:utils.py
示例5: plot_true_and_augmented_data
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def plot_true_and_augmented_data(sample,noised_sample,label,n_examples):
output_dir = os.path.split(FLAGS.output)[0]
# Save augmented data
plt.clf()
fig, ax = plt.subplots(3,1)
for t in range(noised_sample.shape[1]):
ax[t].plot(noised_sample[:,t])
ax[t].set_xlabel('time (samples)')
ax[t].set_ylabel('amplitude')
ax[0].set_title('window {:03d}, cluster_id: {}'.format(n_examples,label))
plt.savefig(os.path.join(output_dir, "augmented_data",
'augmented_{:03d}.pdf'.format(n_examples)))
plt.close()
# Save true data
plt.clf()
fig, ax = plt.subplots(3,1)
for t in range(sample.shape[1]):
ax[t].plot(sample[:,t])
ax[t].set_xlabel('time (samples)')
ax[t].set_ylabel('amplitude')
ax[0].set_title('window {:03d}, cluster_id: {}'.format(n_examples,label))
plt.savefig(os.path.join(output_dir, "true_data",
'true__{:03d}.pdf'.format(n_examples)))
plt.close()
示例6: test_normality_increase_lambert
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def test_normality_increase_lambert(self):
# Generate random data and check that it is more normal after inference
for i, y in enumerate([np.random.standard_cauchy(size=ns), experimental_data]):
print('Distribution %d' % i)
print('Before')
print(('anderson: %0.3f\tshapiro: %0.3f' % (anderson(y)[0], shapiro(y)[0])).expandtabs(30))
stats.probplot(y, dist="norm", plot=plt)
plt.savefig(os.path.join(self.test_dir, '%d_before.png' % i))
plt.clf()
tau = g.igmm(y)
x = g.w_t(y, tau)
print('After')
print(('anderson: %0.3f\tshapiro: %0.3f' % (anderson(x)[0], shapiro(x)[0])).expandtabs(30))
stats.probplot(x, dist="norm", plot=plt)
plt.savefig(os.path.join(self.test_dir, '%d_after.png' % i))
plt.clf()
示例7: check_HDF5
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def check_HDF5(size=64):
"""
Plot images with landmarks to check the processing
"""
# Get hdf5 file
hdf5_file = os.path.join(data_dir, "CelebA_%s_data.h5" % size)
with h5py.File(hdf5_file, "r") as hf:
data_color = hf["data"]
for i in range(data_color.shape[0]):
plt.figure()
img = data_color[i, :, :, :].transpose(1,2,0)
plt.imshow(img)
plt.show()
plt.clf()
plt.close()
示例8: check_HDF5
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def check_HDF5(jpeg_dir, nb_channels):
"""
Plot images with landmarks to check the processing
"""
# Get hdf5 file
file_name = os.path.basename(jpeg_dir.rstrip("/"))
hdf5_file = os.path.join(data_dir, "%s_data.h5" % file_name)
with h5py.File(hdf5_file, "r") as hf:
data_full = hf["train_data_full"]
data_sketch = hf["train_data_sketch"]
for i in range(data_full.shape[0]):
plt.figure()
img = data_full[i, :, :, :].transpose(1,2,0)
img2 = data_sketch[i, :, :, :].transpose(1,2,0)
img = np.concatenate((img, img2), axis=1)
if nb_channels == 1:
plt.imshow(img[:, :, 0], cmap="gray")
else:
plt.imshow(img)
plt.show()
plt.clf()
plt.close()
示例9: check_HDF5
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def check_HDF5(size):
"""
Plot images with landmarks to check the processing
"""
# Get hdf5 file
hdf5_file = os.path.join(data_dir, "lfw_%s_data.h5" % size)
with h5py.File(hdf5_file, "r") as hf:
data_color = hf["data"]
label = hf["labels"]
attrs = label.attrs["label_names"]
for i in range(data_color.shape[0]):
plt.figure(figsize=(20, 10))
img = data_color[i, :, :, :].transpose(1,2,0)[:, :, ::-1]
# Get the 10 labels with highest values
idx = label[i].argsort()[-10:]
plt.xlabel(", ".join(attrs[idx]), fontsize=12)
plt.imshow(img)
plt.show()
plt.clf()
plt.close()
示例10: save_state_images
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def save_state_images(frame_idx, states, net, device="cpu", max_states=200):
ofs = 0
p = np.arange(Vmin, Vmax + DELTA_Z, DELTA_Z)
for batch in np.array_split(states, 64):
states_v = torch.tensor(batch).to(device)
action_prob = net.apply_softmax(net(states_v)).data.cpu().numpy()
batch_size, num_actions, _ = action_prob.shape
for batch_idx in range(batch_size):
plt.clf()
for action_idx in range(num_actions):
plt.subplot(num_actions, 1, action_idx+1)
plt.bar(p, action_prob[batch_idx, action_idx], width=0.5)
plt.savefig("states/%05d_%08d.png" % (ofs + batch_idx, frame_idx))
ofs += batch_size
if ofs >= max_states:
break
示例11: save_transition_images
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def save_transition_images(batch_size, predicted, projected, next_distr, dones, rewards, save_prefix):
for batch_idx in range(batch_size):
is_done = dones[batch_idx]
reward = rewards[batch_idx]
plt.clf()
p = np.arange(Vmin, Vmax + DELTA_Z, DELTA_Z)
plt.subplot(3, 1, 1)
plt.bar(p, predicted[batch_idx], width=0.5)
plt.title("Predicted")
plt.subplot(3, 1, 2)
plt.bar(p, projected[batch_idx], width=0.5)
plt.title("Projected")
plt.subplot(3, 1, 3)
plt.bar(p, next_distr[batch_idx], width=0.5)
plt.title("Next state")
suffix = ""
if reward != 0.0:
suffix = suffix + "_%.0f" % reward
if is_done:
suffix = suffix + "_done"
plt.savefig("%s_%02d%s.png" % (save_prefix, batch_idx, suffix))
示例12: plot_pr
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def plot_pr(auc_score, name, phase, precision, recall, label=None):
pylab.clf()
pylab.figure(num=None, figsize=(5, 4))
pylab.grid(True)
pylab.fill_between(recall, precision, alpha=0.5)
pylab.plot(recall, precision, lw=1)
pylab.xlim([0.0, 1.0])
pylab.ylim([0.0, 1.0])
pylab.xlabel('Recall')
pylab.ylabel('Precision')
pylab.title('P/R curve (AUC=%0.2f) / %s' % (auc_score, label))
filename = name.replace(" ", "_")
pylab.savefig(os.path.join(CHART_DIR, "pr_%s_%s.png" %
(filename, phase)), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:16,代码来源:utils.py
示例13: show_most_informative_features
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def show_most_informative_features(vectorizer, clf, n=20):
c_f = sorted(zip(clf.coef_[0], vectorizer.get_feature_names()))
top = zip(c_f[:n], c_f[:-(n + 1):-1])
for (c1, f1), (c2, f2) in top:
print "\t%.4f\t%-15s\t\t%.4f\t%-15s" % (c1, f1, c2, f2)
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:7,代码来源:utils.py
示例14: plot_log
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [as 别名]
def plot_log():
pylab.clf()
pylab.figure(num=None, figsize=(6, 5))
x = np.arange(0.001, 1, 0.001)
y = np.log(x)
pylab.title('Relationship between probabilities and their logarithm')
pylab.plot(x, y)
pylab.grid(True)
pylab.xlabel('P')
pylab.ylabel('log(P)')
filename = 'log_probs.png'
pylab.savefig(os.path.join(CHART_DIR, filename), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:16,代码来源:utils.py
示例15: plot_feat_hist
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import clf [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