本文整理匯總了Python中matplotlib.image方法的典型用法代碼示例。如果您正苦於以下問題:Python matplotlib.image方法的具體用法?Python matplotlib.image怎麽用?Python matplotlib.image使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib
的用法示例。
在下文中一共展示了matplotlib.image方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: switch_backend
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def switch_backend(newbackend):
"""
Switch the default backend. This feature is **experimental**, and
is only expected to work switching to an image backend. e.g., if
you have a bunch of PostScript scripts that you want to run from
an interactive ipython session, you may want to switch to the PS
backend before running them to avoid having a bunch of GUI windows
popup. If you try to interactively switch from one GUI backend to
another, you will explode.
Calling this command will close all open windows.
"""
close('all')
global _backend_mod, new_figure_manager, draw_if_interactive, _show
matplotlib.use(newbackend, warn=False, force=True)
from matplotlib.backends import pylab_setup
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
示例2: clim
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def clim(vmin=None, vmax=None):
"""
Set the color limits of the current image.
To apply clim to all axes images do::
clim(0, 0.5)
If either *vmin* or *vmax* is None, the image min/max respectively
will be used for color scaling.
If you want to set the clim of multiple images,
use, for example::
for im in gca().get_images():
im.set_clim(0, 0.05)
"""
im = gci()
if im is None:
raise RuntimeError('You must first define an image, eg with imshow')
im.set_clim(vmin, vmax)
draw_if_interactive()
示例3: set_cmap
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def set_cmap(cmap):
"""
Set the default colormap. Applies to the current image if any.
See help(colormaps) for more information.
*cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or
the name of a registered colormap.
See :func:`matplotlib.cm.register_cmap` and
:func:`matplotlib.cm.get_cmap`.
"""
cmap = cm.get_cmap(cmap)
rc('image', cmap=cmap.name)
im = gci()
if im is not None:
im.set_cmap(cmap)
draw_if_interactive()
示例4: get_plot_formats
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def get_plot_formats(config):
default_dpi = {'png': 80, 'hires.png': 200, 'pdf': 200}
formats = []
plot_formats = config.plot_formats
if isinstance(plot_formats, six.string_types):
# String Sphinx < 1.3, Split on , to mimic
# Sphinx 1.3 and later. Sphinx 1.3 always
# returns a list.
plot_formats = plot_formats.split(',')
for fmt in plot_formats:
if isinstance(fmt, six.string_types):
if ':' in fmt:
suffix, dpi = fmt.split(':')
formats.append((str(suffix), int(dpi)))
else:
formats.append((fmt, default_dpi.get(fmt, 80)))
elif type(fmt) in (tuple, list) and len(fmt) == 2:
formats.append((str(fmt[0]), int(fmt[1])))
else:
raise PlotError('invalid image format "%r" in plot_formats' % fmt)
return formats
示例5: get_plot_formats
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def get_plot_formats(config):
default_dpi = {'png': 80, 'hires.png': 200, 'pdf': 200}
formats = []
plot_formats = config.plot_formats
for fmt in plot_formats:
if isinstance(fmt, str):
if ':' in fmt:
suffix, dpi = fmt.split(':')
formats.append((str(suffix), int(dpi)))
else:
formats.append((fmt, default_dpi.get(fmt, 80)))
elif isinstance(fmt, (tuple, list)) and len(fmt) == 2:
formats.append((str(fmt[0]), int(fmt[1])))
else:
raise PlotError('invalid image format "%r" in plot_formats' % fmt)
return formats
示例6: clim
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def clim(vmin=None, vmax=None):
"""
Set the color limits of the current image.
To apply clim to all axes images do::
clim(0, 0.5)
If either *vmin* or *vmax* is None, the image min/max respectively
will be used for color scaling.
If you want to set the clim of multiple images,
use, for example::
for im in gca().get_images():
im.set_clim(0, 0.05)
"""
im = gci()
if im is None:
raise RuntimeError('You must first define an image, e.g., with imshow')
im.set_clim(vmin, vmax)
draw_if_interactive()
示例7: gci
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def gci():
"""
Get the current colorable artist. Specifically, returns the
current :class:`~matplotlib.cm.ScalarMappable` instance (image or
patch collection), or *None* if no images or patch collections
have been defined. The commands :func:`~matplotlib.pyplot.imshow`
and :func:`~matplotlib.pyplot.figimage` create
:class:`~matplotlib.image.Image` instances, and the commands
:func:`~matplotlib.pyplot.pcolor` and
:func:`~matplotlib.pyplot.scatter` create
:class:`~matplotlib.collections.Collection` instances. The
current image is an attribute of the current axes, or the nearest
earlier axes in the current figure that contains an image.
"""
return gcf()._gci()
## Any Artist ##
# (getp is simply imported)
示例8: clim
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def clim(vmin=None, vmax=None):
"""
Set the color limits of the current image.
To apply clim to all axes images do::
clim(0, 0.5)
If either *vmin* or *vmax* is None, the image min/max respectively
will be used for color scaling.
If you want to set the clim of multiple images,
use, for example::
for im in gca().get_images():
im.set_clim(0, 0.05)
"""
im = gci()
if im is None:
raise RuntimeError('You must first define an image, e.g., with imshow')
im.set_clim(vmin, vmax)
示例9: test
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def test(train_loader, model, model2, dir):
totalNumber = 0
errorSum = {'MSE': 0, 'RMSE': 0, 'ABS_REL': 0, 'LG10': 0,
'MAE': 0, 'DELTA1': 0, 'DELTA2': 0, 'DELTA3': 0}
model.eval()
model2.eval()
# if not os.path.exists(dir):
# os.mkdir(dir)
for i, sample_batched in enumerate(train_loader):
image, depth_ = sample_batched['image'], sample_batched['depth']
image = torch.autograd.Variable(image, volatile=True).cuda()
depth_ = torch.autograd.Variable(depth_, volatile=True).cuda(async=True)
depth = model(image)
mask = model2(image)
output = model(image*mask)
batchSize = depth.size(0)
errors = util.evaluateError(output,depth_)
errorSum = util.addErrors(errorSum, errors, batchSize)
totalNumber = totalNumber + batchSize
averageError = util.averageErrors(errorSum, totalNumber)
# mask = mask.squeeze().view(228,304).data.cpu().float().numpy()
# matplotlib.image.imsave(dir+'/mask'+str(i)+'.png', mask)
print('rmse:',np.sqrt(averageError['MSE']))
示例10: region
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def region(self, region):
"Extract a subset of the SARData image defined by a Region object"
s = SARData()
s.hhhh = self.hhhh.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten()
s.hhhv = self.hhhv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten()
s.hvhv = self.hvhv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten()
s.hhvv = self.hhvv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten()
s.hvvv = self.hvvv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten()
s.vvvv = self.vvvv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten()
s.shape = (len(region.range_i), len(region.range_j))
s.size = len(region.range_i) * len(region.range_j)
return s
示例11: masked_region
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def masked_region(self, mask):
"Extract a subset of the SARData image defined by a mask"
assert(mask.shape == self.hhhh.shape)
s = SARData()
for c in ["hhhh", "hhhv", "hvhv", "hhvv", "hvvv", "vvvv"]:
s.__dict__[c] = self.__dict__[c][mask]
s.shape = None
s.size = mask.sum()
return s
示例12: color_composite
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def color_composite(self):
"Color composite of a EMISAR image"
# Take logarithm
green = 10*np.log(self.hhhh.reshape(self.shape)) / np.log(10)
blue = 10*np.log(self.vvvv.reshape(self.shape)) / np.log(10)
red = 10*np.log(self.hvhv.reshape(self.shape)) / np.log(10)
# Normalize
green = matplotlib.colors.normalize(-30, 0, clip=True)(green)
blue = matplotlib.colors.normalize(-30, 0, clip=True)(blue)
red = matplotlib.colors.normalize(-36, -6, clip=True)(red)
# Return as a RGB image
return np.concatenate((red[:,:,None], green[:,:,None], blue[:,:,None]), axis=2)
示例13: rcdefaults
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def rcdefaults():
matplotlib.rcdefaults()
draw_if_interactive()
# The current "image" (ScalarMappable) is retrieved or set
# only via the pyplot interface using the following two
# functions:
示例14: gci
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def gci():
"""
Get the current colorable artist. Specifically, returns the
current :class:`~matplotlib.cm.ScalarMappable` instance (image or
patch collection), or *None* if no images or patch collections
have been defined. The commands :func:`~matplotlib.pyplot.imshow`
and :func:`~matplotlib.pyplot.figimage` create
:class:`~matplotlib.image.Image` instances, and the commands
:func:`~matplotlib.pyplot.pcolor` and
:func:`~matplotlib.pyplot.scatter` create
:class:`~matplotlib.collections.Collection` instances. The
current image is an attribute of the current axes, or the nearest
earlier axes in the current figure that contains an image.
"""
return gcf()._gci()
示例15: sci
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import image [as 別名]
def sci(im):
"""
Set the current image. This image will be the target of colormap
commands like :func:`~matplotlib.pyplot.jet`,
:func:`~matplotlib.pyplot.hot` or
:func:`~matplotlib.pyplot.clim`). The current image is an
attribute of the current axes.
"""
gca()._sci(im)
## Any Artist ##
# (getp is simply imported)