本文整理汇总了Python中matplotlib.pylab.tight_layout方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.tight_layout方法的具体用法?Python pylab.tight_layout怎么用?Python pylab.tight_layout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.tight_layout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_pr_curve
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [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: plot_alignment_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_alignment_to_numpy(alignment, info=None):
fig, ax = plt.subplots(figsize=(6, 4))
im = ax.imshow(alignment, aspect='auto', origin='lower',
interpolation='none')
fig.colorbar(im, ax=ax)
xlabel = 'Decoder timestep'
if info is not None:
xlabel += '\n\n' + info
plt.xlabel(xlabel)
plt.ylabel('Encoder timestep')
plt.tight_layout()
fig.canvas.draw()
data = save_figure_to_numpy(fig)
plt.close()
return data
示例3: show_pred
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def show_pred(images, predictions, ground_truth):
# choose 10 indice from images and visualize them
indice = [np.random.randint(0, len(images)) for i in range(40)]
for i in range(0, 40):
plt.figure()
plt.subplot(1, 3, 1)
plt.tight_layout()
plt.title('deformed image')
plt.imshow(images[indice[i]])
plt.subplot(1, 3, 2)
plt.tight_layout()
plt.title('predicted mask')
plt.imshow(predictions[indice[i]])
plt.subplot(1, 3, 3)
plt.tight_layout()
plt.title('ground truth label')
plt.imshow(ground_truth[indice[i]])
plt.show()
# Load Data Science Bowl 2018 training dataset
示例4: plot_gate_outputs_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_gate_outputs_to_numpy(gate_targets, gate_outputs):
fig, ax = plt.subplots(figsize=(12, 3))
ax.scatter(
range(len(gate_targets)), gate_targets, alpha=0.5, color='green', marker='+', s=1, label='target',
)
ax.scatter(
range(len(gate_outputs)), gate_outputs, alpha=0.5, color='red', marker='.', s=1, label='predicted',
)
plt.xlabel("Frames (Green target, Red predicted)")
plt.ylabel("Gate State")
plt.tight_layout()
fig.canvas.draw()
data = save_figure_to_numpy(fig)
plt.close()
return data
示例5: plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot(params_dir):
model_dirs = [name for name in os.listdir(params_dir)
if os.path.isdir(os.path.join(params_dir, name))]
df = defaultdict(list)
for model_dir in model_dirs:
df[re.sub('_bin_scaled_mono_True_ratio', '', model_dir)] = [
dd.io.load(path)['best_epoch']['validate_objective']
for path in glob.glob(os.path.join(
params_dir, model_dir) + '/*.h5')]
df = pd.DataFrame(dict([(k, pd.Series(v)) for k, v in df.iteritems()]))
df.to_csv(os.path.basename(os.path.normpath(params_dir)))
plt.figure(figsize=(16, 4), dpi=300)
g = sns.boxplot(df)
g.set_xticklabels(df.columns, rotation=45)
plt.tight_layout()
plt.savefig('{}_errors_box_plot.png'.format(
os.path.join(IMAGES_DIRECTORY,
os.path.basename(os.path.normpath(params_dir)))))
示例6: plot_losses
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_losses(losses_d, losses_g, filename):
losses_d = np.array(losses_d)
fig, axes = plt.subplots(3, 2, figsize=(8, 8))
axes = axes.flatten()
axes[0].plot(losses_d[:, 0])
axes[1].plot(losses_d[:, 1])
axes[2].plot(losses_d[:, 2])
axes[3].plot(losses_d[:, 3])
axes[4].plot(losses_g)
axes[0].set_title("losses_d")
axes[1].set_title("losses_d_real")
axes[2].set_title("losses_d_fake")
axes[3].set_title("losses_d_gp")
axes[4].set_title("losses_g")
plt.tight_layout()
plt.savefig(filename)
plt.close()
开发者ID:PacktPublishing,项目名称:Hands-On-Generative-Adversarial-Networks-with-Keras,代码行数:19,代码来源:resnet_wgan_gp_cifar10_train.py
示例7: plot_spectrogram_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_spectrogram_to_numpy(spectrogram):
spectrogram = spectrogram.transpose(1, 0)
fig, ax = plt.subplots(figsize=(12, 3))
im = ax.imshow(spectrogram, aspect="auto", origin="lower",
interpolation='none')
plt.colorbar(im, ax=ax)
plt.xlabel("Frames")
plt.ylabel("Channels")
plt.tight_layout()
fig.canvas.draw()
data = _save_figure_to_numpy(fig)
plt.close()
return data
####################
# PLOT SPECTROGRAM #
####################
开发者ID:andi611,项目名称:Self-Supervised-Speech-Pretraining-and-Representation-Learning,代码行数:21,代码来源:audio.py
示例8: plot1D_mat
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [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)
示例9: plot_spectrogram_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_spectrogram_to_numpy(spectrogram):
fig, ax = plt.subplots(figsize=(12, 3))
im = ax.imshow(spectrogram, aspect="auto", origin="lower",
interpolation='none')
plt.colorbar(im, ax=ax)
plt.xlabel("Frames")
plt.ylabel("Channels")
plt.tight_layout()
fig.canvas.draw()
data = save_figure_to_numpy(fig)
plt.close()
return data
# from https://github.com/NVIDIA/vid2vid/blob/951a52bb38c2aa227533b3731b73f40cbd3843c4/models/networks.py#L17
示例10: plot_spectrogram_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_spectrogram_to_numpy(spectrogram):
fig, ax = plt.subplots(figsize=(12, 3))
im = ax.imshow(spectrogram, aspect="auto", origin="lower",
interpolation='none')
plt.colorbar(im, ax=ax)
plt.xlabel("Frames")
plt.ylabel("Channels")
plt.tight_layout()
fig.canvas.draw()
data = save_figure_to_numpy(fig)
plt.close()
return data
示例11: plot_gate_outputs_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_gate_outputs_to_numpy(gate_targets, gate_outputs):
fig, ax = plt.subplots(figsize=(12, 3))
ax.scatter(list(range(len(gate_targets))), gate_targets, alpha=0.5,
color='green', marker='+', s=1, label='target')
ax.scatter(list(range(len(gate_outputs))), gate_outputs, alpha=0.5,
color='red', marker='.', s=1, label='predicted')
plt.xlabel("Frames (Green target, Red predicted)")
plt.ylabel("Gate State")
plt.tight_layout()
fig.canvas.draw()
data = save_figure_to_numpy(fig)
plt.close()
return data
示例12: show_batch
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def show_batch(sample_batched):
"""Show image with landmarks for a batch of samples."""
images_batch, masks_batch = sample_batched['image'].numpy().astype(np.uint8), sample_batched['mask'].numpy().astype(np.bool)
batch_size = len(images_batch)
for i in range(batch_size):
plt.figure()
plt.subplot(1, 2, 1)
plt.tight_layout()
plt.imshow(images_batch[i].transpose((1, 2, 0)))
plt.subplot(1, 2, 2)
plt.tight_layout()
plt.imshow(np.squeeze(masks_batch[i].transpose((1, 2, 0))))
示例13: plot_waveform_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_waveform_to_numpy(waveform):
fig, ax = plt.subplots(figsize=(12, 3))
ax.plot()
ax.plot(range(len(waveform)), waveform,
linewidth=0.1, alpha=0.7, color='blue')
plt.xlabel("Samples")
plt.ylabel("Amplitude")
plt.ylim(-1, 1)
plt.tight_layout()
fig.canvas.draw()
data = save_figure_to_numpy(fig)
plt.close()
return data
示例14: show_batch
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def show_batch(sample_batched):
"""Show image with landmarks for a batch of samples."""
images_batch, masks_batch = sample_batched['image'].numpy().astype(np.uint8), sample_batched['mask'].numpy().astype(np.bool)
batch_size = len(images_batch)
for i in range(batch_size):
plt.figure()
plt.subplot(1, 2, 1)
plt.tight_layout()
plt.imshow(images_batch[i].transpose((1, 2, 0)))
plt.subplot(1, 2, 2)
plt.tight_layout()
plt.imshow(np.squeeze(masks_batch[i].transpose((1, 2, 0))))
# Load Data Science Bowl 2018 training dataset
示例15: plot_alignment_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import tight_layout [as 别名]
def plot_alignment_to_numpy(alignment, info=None):
fig, ax = plt.subplots(figsize=(6, 4))
im = ax.imshow(alignment, aspect='auto', origin='lower', interpolation='none')
fig.colorbar(im, ax=ax)
xlabel = 'Decoder timestep'
if info is not None:
xlabel += '\n\n' + info
plt.xlabel(xlabel)
plt.ylabel('Encoder timestep')
plt.tight_layout()
fig.canvas.draw()
data = save_figure_to_numpy(fig)
plt.close()
return data