本文整理汇总了Python中matplotlib.pylab.imshow方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.imshow方法的具体用法?Python pylab.imshow怎么用?Python pylab.imshow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.imshow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_png_chess_dp_vertex
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def generate_png_chess_dp_vertex(self):
"""Produces pictures of the dominant product vertex a chessboard convention"""
import matplotlib.pylab as plt
plt.ioff()
dab2v = self.get_dp_vertex_doubly_sparse()
for i, ab in enumerate(dab2v):
fname = "chess-v-{:06d}.png".format(i)
print('Matrix No.#{}, Size: {}, Type: {}'.format(i+1, ab.shape, type(ab)), fname)
if type(ab) != 'numpy.ndarray': ab = ab.toarray()
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_aspect('equal')
plt.imshow(ab, interpolation='nearest', cmap=plt.cm.ocean)
plt.colorbar()
plt.savefig(fname)
plt.close(fig)
示例2: plotallfuncs
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def plotallfuncs(allfuncs=allfuncs):
from matplotlib import pylab as pl
pl.ioff()
nnt = NNTester(npoints=1000)
lpt = LinearTester(npoints=1000)
for func in allfuncs:
print(func.title)
nnt.plot(func, interp=False, plotter='imshow')
pl.savefig('%s-ref-img.png' % func.func_name)
nnt.plot(func, interp=True, plotter='imshow')
pl.savefig('%s-nn-img.png' % func.func_name)
lpt.plot(func, interp=True, plotter='imshow')
pl.savefig('%s-lin-img.png' % func.func_name)
nnt.plot(func, interp=False, plotter='contour')
pl.savefig('%s-ref-con.png' % func.func_name)
nnt.plot(func, interp=True, plotter='contour')
pl.savefig('%s-nn-con.png' % func.func_name)
lpt.plot(func, interp=True, plotter='contour')
pl.savefig('%s-lin-con.png' % func.func_name)
pl.ion()
示例3: __init__
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def __init__(self, name = "unknown", data = -1, is_show = False):
self.name = name
self.data = data
self.size = np.shape(self.data)
self.is_show = is_show
self.color_space = "unknown"
self.bayer_pattern = "unknown"
self.channel_gain = (1.0, 1.0, 1.0, 1.0)
self.bit_depth = 0
self.black_level = (0, 0, 0, 0)
self.white_level = (1, 1, 1, 1)
self.color_matrix = [[1., .0, .0],\
[.0, 1., .0],\
[.0, .0, 1.]] # xyz2cam
self.min_value = np.min(self.data)
self.max_value = np.max(self.data)
self.data_type = self.data.dtype
# Display image only isShow = True
if (self.is_show):
plt.imshow(self.data)
plt.show()
示例4: plotallfuncs
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def plotallfuncs(allfuncs=allfuncs):
from matplotlib import pylab as pl
pl.ioff()
nnt = NNTester(npoints=1000)
lpt = LinearTester(npoints=1000)
for func in allfuncs:
print(func.title)
nnt.plot(func, interp=False, plotter='imshow')
pl.savefig('%s-ref-img.png' % func.__name__)
nnt.plot(func, interp=True, plotter='imshow')
pl.savefig('%s-nn-img.png' % func.__name__)
lpt.plot(func, interp=True, plotter='imshow')
pl.savefig('%s-lin-img.png' % func.__name__)
nnt.plot(func, interp=False, plotter='contour')
pl.savefig('%s-ref-con.png' % func.__name__)
nnt.plot(func, interp=True, plotter='contour')
pl.savefig('%s-nn-con.png' % func.__name__)
lpt.plot(func, interp=True, plotter='contour')
pl.savefig('%s-lin-con.png' % func.__name__)
pl.ion()
示例5: _show_video
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def _show_video(video, fps=10):
# Import matplotlib/pylab only if needed
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pylab as pl
pl.style.use('ggplot')
pl.axis('off')
if fps < 0:
fps = 25
video /= 255. # Pylab works in [0, 1] range
img = None
pause_length = 1. / fps
try:
for f in range(video.shape[0]):
im = video[f, :, :, :]
if img is None:
img = pl.imshow(im)
else:
img.set_data(im)
pl.pause(pause_length)
pl.draw()
except:
pass
示例6: show_pred
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [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
示例7: matrix
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def matrix(msg, mobj):
"""
Interpret a user string, convert it to a list and graph it as a matrix
Uses ast.literal_eval to parse input into a list
"""
fname = bot_data("{}.png".format(mobj.author.id))
try:
list_input = literal_eval(msg)
if not isinstance(list_input, list):
raise ValueError("Not a list")
m = np_matrix(list_input)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_aspect('equal')
plt.imshow(m, interpolation='nearest', cmap=plt.cm.ocean)
plt.colorbar()
plt.savefig(fname)
await client.send_file(mobj.channel, fname)
f_remove(fname)
return
except Exception as ex:
logger("!matrix: {}".format(ex))
return await client.send_message(mobj.channel, "Failed to render graph")
示例8: _repr_html_
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def _repr_html_(self):
from . import variable_describe
def _plot(fn):
from PIL import Image
try:
import matplotlib.pylab as plt
t = np.array(Image.open(fn))
plt.figure()
plt.imshow(self._crop(t))
plt.axis('off')
return "<img src='data:image/png;base64," + variable_describe._plot_to_string() + "'>"
except:
return "<br/>Failed to open."
s = "<b>ImageSequence</b> size="+str(self.size)
s += ", offset = "+str(self.offset)
s += ", repeat = "+str(self.repeat)
s += ", is_color = "+str(self.is_color)
s += ", [frame "+str(self.i)+"/"+str(len(self))+"]"
s += "<div style='background:#ff;padding:10px'><b>Input Images:</b>"
for t in np.unique(self.file_list)[:10]:
s += "<div style='background:#fff; margin:10px;padding:10px; border-left: 4px solid #eee;'>"+str(t)+": "+_plot(t)+"</div>"
s += "</div>"
return s
示例9: calibrate_division_model_test
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def calibrate_division_model_test():
img = rgb2gray(plt.imread('test/kamera2.png'))
y0 = np.array(img.shape)[::-1][np.newaxis].T / 2.
z_n = np.linalg.norm(np.array(img.shape) / 2.)
points = pilab_annotate_load('test/kamera2_lines.xml')
points_per_line = 5
num_lines = points.shape[0] / points_per_line
lines_coords = np.array([points[i * points_per_line:i * points_per_line + points_per_line] for i in xrange(num_lines)])
c = camera.calibrate_division_model(lines_coords, y0, z_n)
import matplotlib.cm as cm
plt.figure()
plt.imshow(img, cmap=cm.gray)
for line in xrange(num_lines):
x = lines_coords[line, :, 0]
plt.plot(x, lines_coords[line, :, 1], 'g')
mc = camera.fit_line(lines_coords[line].T)
plt.plot(x, mc[0] * x + mc[1], 'y')
xy = c.undistort(lines_coords[line].T)
plt.plot(xy[0, :], xy[1, :], 'r')
plt.show()
plt.close()
示例10: check_HDF5
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [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()
示例11: check_HDF5
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [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()
示例12: check_HDF5
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [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()
示例13: format_plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def format_plot(X, epoch=None, title=None, figsize=(15, 10)):
plt.figure(figsize=figsize)
if X.shape[-1] == 1:
plt.imshow(X[:, :, 0], cmap="gray")
else:
plt.imshow(X)
plt.axis("off")
plt.gca().xaxis.set_major_locator(mp.ticker.NullLocator())
plt.gca().yaxis.set_major_locator(mp.ticker.NullLocator())
if epoch is not None and title is None:
save_path = os.path.join(FLAGS.fig_dir, "current_batch_%s.png" % epoch)
elif epoch is not None and title is not None:
save_path = os.path.join(FLAGS.fig_dir, "%s_%s.png" % (title, epoch))
elif title is not None:
save_path = os.path.join(FLAGS.fig_dir, "%s.png" % title)
plt.savefig(save_path, bbox_inches='tight', pad_inches=0)
plt.clf()
plt.close()
示例14: plot_spectrogram_to_numpy
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [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
示例15: plot_spectrograms
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import imshow [as 别名]
def plot_spectrograms(model, mag_val, mag_val_hat):
'''
Routine for plotting magnitude and phase spectorgrams
'''
plt.figure(1)
plt.imshow(mag_val.data.cpu().numpy()[0, :, :].T, aspect='auto', origin='lower')
plt.title('Initial magnitude')
savefig('mag.png')
plt.figure(2) # <---- Check this out! Some "sub-harmonic" content is generated for the compressor if the analysis weights make only small perturbations
plt.imshow(mag_val_hat.data.cpu().numpy()[0, :, :].T, aspect='auto', origin='lower')
plt.title('Processed magnitude')
savefig('mag_hat.png')
#if isinstance(model, nn_proc.AsymMPAEC): # Plot the spectrograms
plt.matshow(model.mpaec.dft_analysis.conv_analysis_real.weight.data.cpu().numpy().astype(float)[:, 0, :] + 1)
plt.title('Conv-Analysis Real')
savefig('conv_anal_real.png')
plt.matshow(model.mpaec.dft_analysis.conv_analysis_imag.weight.data.cpu().numpy().astype(float)[:, 0, :])
plt.title('Conv-Analysis Imag')
savefig('conv_anal_imag.png')
plt.matshow(model.mpaec.dft_synthesis.conv_synthesis_real.weight.data.cpu().numpy().astype(float)[:, 0, :])
plt.title('Conv-Synthesis Real')
savefig('conv_synth_real.png')
plt.matshow(model.mpaec.dft_synthesis.conv_synthesis_imag.weight.data.cpu().numpy().astype(float)[:, 0, :])
plt.title('Conv-Synthesis Imag')
savefig('conv_synth_imag.png')
return