本文整理汇总了Python中matplotlib.pylab.suptitle方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.suptitle方法的具体用法?Python pylab.suptitle怎么用?Python pylab.suptitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.suptitle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_valdata
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import suptitle [as 别名]
def plot_valdata(x_val_cuda, knobs_val_cuda, y_val_cuda, y_val_hat_cuda, effect, \
epoch, loss_val, file_prefix='val_data', num_plots=50, target_size=None):
x_size = len(x_val_cuda.data.cpu().numpy()[0])
if target_size is None:
y_size = len(y_val_cuda.data.cpu().numpy()[0])
else:
y_size = target_size
t_small = range(x_size-y_size, x_size)
for plot_i in range(0, num_plots):
x_val = x_val_cuda.data.cpu().numpy()
knobs_w = effect.knobs_wc( knobs_val_cuda.data.cpu().numpy()[plot_i,:] )
plt.figure(plot_i,figsize=(6,8))
titlestr = f'{effect.name} Val data, epoch {epoch+1}, loss_val = {loss_val.item():.3e}\n'
for i in range(len(effect.knob_names)):
titlestr += f'{effect.knob_names[i]} = {knobs_w[i]:.2f}'
if i < len(effect.knob_names)-1: titlestr += ', '
plt.suptitle(titlestr)
plt.subplot(3, 1, 1)
plt.plot(x_val[plot_i, :], 'b', label='Input')
plt.ylim(-1,1)
plt.xlim(0,x_size)
plt.legend()
plt.subplot(3, 1, 2)
y_val = y_val_cuda.data.cpu().numpy()
plt.plot(t_small, y_val[plot_i, -y_size:], 'r', label='Target')
plt.xlim(0,x_size)
plt.ylim(-1,1)
plt.legend()
plt.subplot(3, 1, 3)
plt.plot(t_small, y_val[plot_i, -y_size:], 'r', label='Target')
y_val_hat = y_val_hat_cuda.data.cpu().numpy()
plt.plot(t_small, y_val_hat[plot_i, -y_size:], c=(0,0.5,0,0.85), label='Predicted')
plt.ylim(-1,1)
plt.xlim(0,x_size)
plt.legend()
filename = file_prefix + '_' + str(plot_i) + '.png'
savefig(filename)
return
示例2: plot_intensities
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import suptitle [as 别名]
def plot_intensities(self, figsize=(10, 6), sharex=False, sharey=False):
"""Plot intensities estimated by the penalized model. The intensities
subfigures are plotted on two columns.
Parameters
----------
figsize : `tuple`, default=(10, 6)
Size of the figure
sharex : `bool`, default=False
Constrain the x axes to have the same range.
sharey : `bool`, default=False
Constrain the y axes to have the same range.
Returns
-------
fig : `matplotlib.figure.Figure`
Figure to be plotted
axarr : `numpy.ndarray`, `dtype=object`
`matplotlib.axes._subplots.AxesSubplot` objects associated to each
intensity subplot.
"""
n_rows = int(np.ceil(self.n_features / 2))
remove_last_plot = self.n_features % 2 != 0
fig, axarr = plt.subplots(n_rows, 2, sharex=sharex, sharey=sharey,
figsize=figsize)
for i, c in enumerate(self.coeffs):
self._plot_intensity(axarr[i // 2][i % 2], c, None, None)
plt.suptitle('Estimated (penalized) relative risks')
axarr[0][1].legend(loc='upper right')
[ax[0].set_ylabel('Relative incidence') for ax in axarr]
[ax.set_xlabel('Time after exposure start') for ax in axarr[-1]]
if remove_last_plot:
fig.delaxes(axarr[-1][-1])
return fig, axarr
示例3: plot_tang
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import suptitle [as 别名]
def plot_tang(X, Y, Z, title, npts=None):
fig = plt.figure()
ax = fig.gca(projection='3d')
# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap="viridis",
linewidth=0, antialiased=False)
# Customize the z axis.
ax.set_zlim(-100, 250)
ax.zaxis.set_tick_params(pad=8)
ax.zaxis.set_major_locator(LinearLocator(5))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
if "teacher" in title:
plt.suptitle("Teacher model")
if "student" in title and "sobolev" not in title:
assert (npts is not None)
plt.suptitle("Student model %s training pts" % npts)
if "sobolev" in title:
assert (npts is not None)
plt.suptitle("Student model %s training pts + Sobolev" % npts)
else:
plt.suptitle("Styblinski Tang function")
plt.savefig(title)
示例4: plot_confidence_intervals
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import suptitle [as 别名]
def plot_confidence_intervals(self, figsize=(10, 6), sharex=False,
sharey=False):
"""Plot intensities estimated by the penalized model. The intensities
subfigures are plotted on two columns.
Parameters
----------
figsize : `tuple`, default=(10, 6)
Size of the figure
sharex : `bool`, default=False
Constrain the x axes to have the same range.
sharey : `bool`, default=False
Constrain the y axes to have the same range.
Returns
-------
fig : `matplotlib.figure.Figure`
Figure to be plotted
axarr : `numpy.ndarray`, `dtype=object`
`matplotlib.axes._subplots.AxesSubplot` objects associated to each
intensity subplot
"""
n_rows = int(np.ceil(self.n_features / 2))
remove_last_plot = (self.n_features % 2 != 0)
fig, axarr = plt.subplots(n_rows, 2, sharex=sharex, sharey=sharey,
figsize=figsize)
ci = self.confidence_intervals
coeffs = ci['refit_coeffs']
lb = ci['lower_bound']
ub = ci['upper_bound']
for i, c in enumerate(coeffs):
self._plot_intensity(axarr[i // 2][i % 2], c, lb[i], ub[i])
plt.suptitle('Estimated relative risks with 95% confidence bands')
axarr[0][1].legend(loc='best')
[ax[0].set_ylabel('Relative incidence') for ax in axarr]
[ax.set_xlabel('Time after exposure start') for ax in axarr[-1]]
if remove_last_plot:
fig.delaxes(axarr[-1][-1])
return fig, axarr
示例5: plot_generated_toy_batch
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import suptitle [as 别名]
def plot_generated_toy_batch(X_real, generator_model, discriminator_model, noise_dim, gen_iter, noise_scale=0.5):
# Generate images
X_gen = sample_noise(noise_scale, 10000, noise_dim)
X_gen = generator_model.predict(X_gen)
# Get some toy data to plot KDE of real data
data = load_toy(pts_per_mixture=200)
x = data[:, 0]
y = data[:, 1]
xmin, xmax = -1.5, 1.5
ymin, ymax = -1.5, 1.5
# Peform the kernel density estimate
xx, yy = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
positions = np.vstack([xx.ravel(), yy.ravel()])
values = np.vstack([x, y])
kernel = stats.gaussian_kde(values)
f = np.reshape(kernel(positions).T, xx.shape)
# Plot the contour
fig = plt.figure(figsize=(10,10))
plt.suptitle("Generator iteration %s" % gen_iter, fontweight="bold", fontsize=22)
ax = fig.gca()
ax.contourf(xx, yy, f, cmap='Blues', vmin=np.percentile(f,80), vmax=np.max(f), levels=np.linspace(0.25, 0.85, 30))
# Also plot the contour of the discriminator
delta = 0.025
xmin, xmax = -1.5, 1.5
ymin, ymax = -1.5, 1.5
# Create mesh
XX, YY = np.meshgrid(np.arange(xmin, xmax, delta), np.arange(ymin, ymax, delta))
arr_pos = np.vstack((np.ravel(XX), np.ravel(YY))).T
# Get Z = predictions
ZZ = discriminator_model.predict(arr_pos)
ZZ = ZZ.reshape(XX.shape)
# Plot contour
ax.contour(XX, YY, ZZ, cmap="Blues", levels=np.linspace(0.25, 0.85, 10))
dy, dx = np.gradient(ZZ)
# Add streamlines
# plt.streamplot(XX, YY, dx, dy, linewidth=0.5, cmap="magma", density=1, arrowsize=1)
# Scatter generated data
plt.scatter(X_gen[:1000, 0], X_gen[:1000, 1], s=20, color="coral", marker="o")
l_gen = plt.Line2D((0,1),(0,0), color='coral', marker='o', linestyle='', markersize=20)
l_D = plt.Line2D((0,1),(0,0), color='steelblue', linewidth=3)
l_real = plt.Rectangle((0, 0), 1, 1, fc="steelblue")
# Create legend from custom artist/label lists
# bbox_to_anchor = (0.4, 1)
ax.legend([l_real, l_D, l_gen], ['Real data KDE', 'Discriminator contour',
'Generated data'], fontsize=18, loc="upper left")
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax + 0.8)
plt.savefig("../../figures/toy_dataset_iter%s.jpg" % gen_iter)
plt.clf()
plt.close()