本文整理汇总了Python中matplotlib.cbook.safe_masked_invalid方法的典型用法代码示例。如果您正苦于以下问题:Python cbook.safe_masked_invalid方法的具体用法?Python cbook.safe_masked_invalid怎么用?Python cbook.safe_masked_invalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.cbook
的用法示例。
在下文中一共展示了cbook.safe_masked_invalid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_data
# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import safe_masked_invalid [as 别名]
def set_data(self, A):
"""
Set the image array
ACCEPTS: numpy/PIL Image A
"""
# check if data is PIL Image without importing Image
if hasattr(A, 'getpixel'):
self._A = pil_to_array(A)
else:
self._A = cbook.safe_masked_invalid(A)
if (self._A.dtype != np.uint8 and
not np.can_cast(self._A.dtype, np.float)):
raise TypeError("Image data can not convert to float")
if (self._A.ndim not in (2, 3) or
(self._A.ndim == 3 and self._A.shape[-1] not in (3, 4))):
raise TypeError("Invalid dimensions for image data")
self._imcache = None
self._rgbacache = None
self._oldxslice = None
self._oldyslice = None
示例2: set_data
# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import safe_masked_invalid [as 别名]
def set_data(self, x, y, A):
"""
Set the grid for the pixel centers, and the pixel values.
*x* and *y* are monotonic 1-D ndarrays of lengths N and M,
respectively, specifying pixel centers
*A* is an (M,N) ndarray or masked array of values to be
colormapped, or a (M,N,3) RGB array, or a (M,N,4) RGBA
array.
"""
x = np.array(x, np.float32)
y = np.array(y, np.float32)
A = cbook.safe_masked_invalid(A, copy=True)
if not (x.ndim == y.ndim == 1 and A.shape[0:2] == y.shape + x.shape):
raise TypeError("Axes don't match array shape")
if A.ndim not in [2, 3]:
raise TypeError("Can only plot 2D or 3D data")
if A.ndim == 3 and A.shape[2] not in [1, 3, 4]:
raise TypeError("3D arrays must have three (RGB) "
"or four (RGBA) color components")
if A.ndim == 3 and A.shape[2] == 1:
A.shape = A.shape[0:2]
self._A = A
self._Ax = x
self._Ay = y
self._imcache = None
self.stale = True
示例3: set_data
# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import safe_masked_invalid [as 别名]
def set_data(self, A):
"""
Set the image array.
Note that this function does *not* update the normalization used.
Parameters
----------
A : array-like
"""
self._A = cbook.safe_masked_invalid(A, copy=True)
if (self._A.dtype != np.uint8 and
not np.can_cast(self._A.dtype, float, "same_kind")):
raise TypeError("Image data cannot be converted to float")
if not (self._A.ndim == 2
or self._A.ndim == 3 and self._A.shape[-1] in [3, 4]):
raise TypeError("Invalid dimensions for image data")
if self._A.ndim == 3:
# If the input data has values outside the valid range (after
# normalisation), we issue a warning and then clip X to the bounds
# - otherwise casting wraps extreme values, hiding outliers and
# making reliable interpretation impossible.
high = 255 if np.issubdtype(self._A.dtype, np.integer) else 1
if self._A.min() < 0 or high < self._A.max():
_log.warning(
'Clipping input data to the valid range for imshow with '
'RGB data ([0..1] for floats or [0..255] for integers).'
)
self._A = np.clip(self._A, 0, high)
# Cast unsupported integer types to uint8
if self._A.dtype != np.uint8 and np.issubdtype(self._A.dtype,
np.integer):
self._A = self._A.astype(np.uint8)
self._imcache = None
self._rgbacache = None
self.stale = True