本文整理汇总了Python中matplotlib.transforms.IdentityTransform.frozen方法的典型用法代码示例。如果您正苦于以下问题:Python IdentityTransform.frozen方法的具体用法?Python IdentityTransform.frozen怎么用?Python IdentityTransform.frozen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.transforms.IdentityTransform
的用法示例。
在下文中一共展示了IdentityTransform.frozen方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_image
# 需要导入模块: from matplotlib.transforms import IdentityTransform [as 别名]
# 或者: from matplotlib.transforms.IdentityTransform import frozen [as 别名]
#.........这里部分代码省略.........
if not unsampled:
created_rgba_mask = False
if A.ndim not in (2, 3):
raise ValueError("Invalid dimensions, got %s" % (A.shape,))
if A.ndim == 2:
A = self.norm(A)
if A.dtype.kind == 'f':
# If the image is greyscale, convert to RGBA and
# use the extra channels for resizing the over,
# under, and bad pixels. This is needed because
# Agg's resampler is very aggressive about
# clipping to [0, 1] and we use out-of-bounds
# values to carry the over/under/bad information
rgba = np.empty((A.shape[0], A.shape[1], 4), dtype=A.dtype)
rgba[..., 0] = A # normalized data
# this is to work around spurious warnings coming
# out of masked arrays.
with np.errstate(invalid='ignore'):
rgba[..., 1] = A < 0 # under data
rgba[..., 2] = A > 1 # over data
rgba[..., 3] = ~A.mask # bad data
A = rgba
output = np.zeros((out_height, out_width, 4),
dtype=A.dtype)
alpha = 1.0
created_rgba_mask = True
else:
# colormap norms that output integers (ex NoNorm
# and BoundaryNorm) to RGBA space before
# interpolating. This is needed due to the
# Agg resampler only working on floats in the
# range [0, 1] and because interpolating indexes
# into an arbitrary LUT may be problematic.
#
# This falls back to interpolating in RGBA space which
# can produce it's own artifacts of colors not in the map
# showing up in the final image.
A = self.cmap(A, alpha=self.get_alpha(), bytes=True)
if not created_rgba_mask:
# Always convert to RGBA, even if only RGB input
if A.shape[2] == 3:
A = _rgb_to_rgba(A)
elif A.shape[2] != 4:
raise ValueError("Invalid dimensions, got %s" % (A.shape,))
output = np.zeros((out_height, out_width, 4), dtype=A.dtype)
alpha = self.get_alpha()
if alpha is None:
alpha = 1.0
_image.resample(
A, output, t, _interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
if created_rgba_mask:
# Convert back to a masked greyscale array so
# colormapping works correctly
hid_output = output
output = np.ma.masked_array(
hid_output[..., 0], hid_output[..., 3] < 0.5)
# relabel under data
output[hid_output[..., 1] > .5] = -1
# relabel over data
output[hid_output[..., 2] > .5] = 2
output = self.to_rgba(output, bytes=True, norm=False)
# Apply alpha *after* if the input was greyscale without a mask
if A.ndim == 2 or created_rgba_mask:
alpha = self.get_alpha()
if alpha is not None and alpha != 1.0:
alpha_channel = output[:, :, 3]
alpha_channel[:] = np.asarray(
np.asarray(alpha_channel, np.float32) * alpha,
np.uint8)
else:
if self._imcache is None:
self._imcache = self.to_rgba(A, bytes=True, norm=(A.ndim == 2))
output = self._imcache
# Subset the input image to only the part that will be
# displayed
subset = TransformedBbox(
clip_bbox, t0.frozen().inverted()).frozen()
output = output[
int(max(subset.ymin, 0)):
int(min(subset.ymax + 1, output.shape[0])),
int(max(subset.xmin, 0)):
int(min(subset.xmax + 1, output.shape[1]))]
t = Affine2D().translate(
int(max(subset.xmin, 0)), int(max(subset.ymin, 0))) + t
return output, clipped_bbox.x0, clipped_bbox.y0, t
示例2: _make_image
# 需要导入模块: from matplotlib.transforms import IdentityTransform [as 别名]
# 或者: from matplotlib.transforms.IdentityTransform import frozen [as 别名]
#.........这里部分代码省略.........
in_bbox.width / A.shape[1],
in_bbox.height / A.shape[0])
.translate(in_bbox.x0, in_bbox.y0)
+ self.get_transform())
t = (t0
+ Affine2D().translate(
-clipped_bbox.x0,
-clipped_bbox.y0)
.scale(magnification, magnification))
# So that the image is aligned with the edge of the axes, we want
# to round up the output width to the next integer. This also
# means scaling the transform just slightly to account for the
# extra subpixel.
if (t.is_affine and round_to_pixel_border and
(out_width_base % 1.0 != 0.0 or
out_height_base % 1.0 != 0.0)):
out_width = int(ceil(out_width_base) + 1)
out_height = int(ceil(out_height_base) + 1)
extra_width = (out_width - out_width_base) / out_width_base
extra_height = (out_height - out_height_base) / out_height_base
t += Affine2D().scale(
1.0 + extra_width, 1.0 + extra_height)
else:
out_width = int(out_width_base)
out_height = int(out_height_base)
if not unsampled:
created_rgba_mask = False
if A.ndim == 2:
A = self.norm(A)
# If the image is greyscale, convert to RGBA with the
# correct alpha channel for resizing
rgba = np.empty((A.shape[0], A.shape[1], 4), dtype=A.dtype)
rgba[..., 0:3] = np.expand_dims(A, 2)
if A.dtype.kind == 'f':
rgba[..., 3] = ~A.mask
else:
rgba[..., 3] = np.where(A.mask, 0, np.iinfo(A.dtype).max)
A = rgba
output = np.zeros((out_height, out_width, 4), dtype=A.dtype)
alpha = 1.0
created_rgba_mask = True
elif A.ndim == 3:
# Always convert to RGBA, even if only RGB input
if A.shape[2] == 3:
A = _rgb_to_rgba(A)
elif A.shape[2] != 4:
raise ValueError("Invalid dimensions, got %s" % (A.shape,))
output = np.zeros((out_height, out_width, 4), dtype=A.dtype)
alpha = self.get_alpha()
if alpha is None:
alpha = 1.0
else:
raise ValueError("Invalid dimensions, got %s" % (A.shape,))
_image.resample(
A, output, t, _interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
if created_rgba_mask:
# Convert back to a masked greyscale array so
# colormapping works correctly
output = np.ma.masked_array(
output[..., 0], output[..., 3] < 0.5)
output = self.to_rgba(output, bytes=True, norm=False)
# Apply alpha *after* if the input was greyscale without a mask
if A.ndim == 2 or created_rgba_mask:
alpha = self.get_alpha()
if alpha is not None and alpha != 1.0:
alpha_channel = output[:, :, 3]
alpha_channel[:] = np.asarray(
np.asarray(alpha_channel, np.float32) * alpha,
np.uint8)
else:
if self._imcache is None:
self._imcache = self.to_rgba(A, bytes=True, norm=(A.ndim == 2))
output = self._imcache
# Subset the input image to only the part that will be
# displayed
subset = TransformedBbox(
clip_bbox, t0.frozen().inverted()).frozen()
output = output[
int(max(subset.ymin, 0)):
int(min(subset.ymax + 1, output.shape[0])),
int(max(subset.xmin, 0)):
int(min(subset.xmax + 1, output.shape[1]))]
t = Affine2D().translate(
int(max(subset.xmin, 0)), int(max(subset.ymin, 0))) + t
return output, clipped_bbox.x0, clipped_bbox.y0, t
示例3: _make_image_special
# 需要导入模块: from matplotlib.transforms import IdentityTransform [as 别名]
# 或者: from matplotlib.transforms.IdentityTransform import frozen [as 别名]
#.........这里部分代码省略.........
#alpha = self.get_alpha()
new_density = np.zeros((out_height, out_width),
dtype=density.dtype)
_image.resample(density, new_density,
t,
_interpd_[self.get_interpolation()],
self.get_resample(), 1.0,
self.get_filternorm() or 0.0,
self.get_filterrad() or 0.0)
# we are done with A_scaled now, remove from namespace
# to be sure!
del A_scaled
# un-scale the resampled data to approximately the
# original range things that interpolated to above /
# below the original min/max will still be above /
# below, but possibly clipped in the case of higher order
# interpolation + drastically changing data.
A_resampled -= 0.1
if a_min != a_max:
A_resampled *= ((a_max - a_min) / 0.8)
A_resampled += a_min
# if using NoNorm, cast back to the original datatype
if isinstance(self.norm, mcolors.NoNorm):
A_resampled = A_resampled.astype(A.dtype)
mask = np.empty(A.shape, dtype=np.float32)
if A.mask.shape == A.shape:
# this is the case of a nontrivial mask
mask[:] = np.where(A.mask, np.float32(np.nan),
np.float32(1))
else:
mask[:] = 1
# we always have to interpolate the mask to account for
# non-affine transformations
out_mask = np.zeros((out_height, out_width),
dtype=mask.dtype)
_image.resample(mask, out_mask,
t,
_interpd_[self.get_interpolation()],
True, 1,
self.get_filternorm() or 0.0,
self.get_filterrad() or 0.0)
# we are done with the mask, delete from namespace to be sure!
del mask
# Agg updates the out_mask in place. If the pixel has
# no image data it will not be updated (and still be 0
# as we initialized it), if input data that would go
# into that output pixel than it will be `nan`, if all
# the input data for a pixel is good it will be 1, and
# if there is _some_ good data in that output pixel it
# will be between [0, 1] (such as a rotated image).
out_alpha = np.array(out_mask)
out_mask = np.isnan(out_mask)
out_alpha[out_mask] = 1
new_alpha = alpha_from_densities(new_density, tresfrac=self.c_alpha_log_tresh, scaleval=self.c_alpha_log_enhance, logscale=self.c_alpha_logdensity)
out_alpha *= new_alpha
# mask and run through the norm
output = self.norm(np.ma.masked_array(A_resampled, out_mask))
# at this point output is either a 2D array of normed data
# (of int or float)
# or an RGBA array of re-sampled input
output = self.to_rgba(output, bytes=True, norm=False)
# output is now a correctly sized RGBA array of uint8
# Apply alpha *after* if the input was greyscale without a mask
if A.ndim == 2:
# alpha = self.get_alpha()
# if alpha is None:
# alpha = 1
alpha = 1
alpha_channel = output[:, :, 3]
alpha_channel[:] = np.asarray(
np.asarray(alpha_channel, np.float32) * out_alpha * alpha,
np.uint8)
else:
if self._imcache is None:
self._imcache = self.to_rgba(A, bytes=True, norm=(A.ndim == 2))
output = self._imcache
# Subset the input image to only the part that will be
# displayed
subset = TransformedBbox(
clip_bbox, t0.frozen().inverted()).frozen()
output = output[
int(max(subset.ymin, 0)):
int(min(subset.ymax + 1, output.shape[0])),
int(max(subset.xmin, 0)):
int(min(subset.xmax + 1, output.shape[1]))]
t = Affine2D().translate(
int(max(subset.xmin, 0)), int(max(subset.ymin, 0))) + t
return output, clipped_bbox.x0, clipped_bbox.y0, t