MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / set_data

Method set_data

site-packages/matplotlib/image.py:620–667  ·  view source on GitHub ↗

Set the image array. Note that this function does *not* update the normalization used. Parameters ---------- A : array-like

(self, A)

Source from the content-addressed store, hash-verified

618 _png.write_png(im, fname)
619
620 def set_data(self, A):
621 """
622 Set the image array.
623
624 Note that this function does *not* update the normalization used.
625
626 Parameters
627 ----------
628 A : array-like
629 """
630 # check if data is PIL Image without importing Image
631 if hasattr(A, 'getpixel'):
632 if A.mode == 'L':
633 # greyscale image, but our logic assumes rgba:
634 self._A = pil_to_array(A.convert('RGBA'))
635 else:
636 self._A = pil_to_array(A)
637 else:
638 self._A = cbook.safe_masked_invalid(A, copy=True)
639
640 if (self._A.dtype != np.uint8 and
641 not np.can_cast(self._A.dtype, float, "same_kind")):
642 raise TypeError("Image data cannot be converted to float")
643
644 if not (self._A.ndim == 2
645 or self._A.ndim == 3 and self._A.shape[-1] in [3, 4]):
646 raise TypeError("Invalid dimensions for image data")
647
648 if self._A.ndim == 3:
649 # If the input data has values outside the valid range (after
650 # normalisation), we issue a warning and then clip X to the bounds
651 # - otherwise casting wraps extreme values, hiding outliers and
652 # making reliable interpretation impossible.
653 high = 255 if np.issubdtype(self._A.dtype, np.integer) else 1
654 if self._A.min() < 0 or high < self._A.max():
655 _log.warning(
656 'Clipping input data to the valid range for imshow with '
657 'RGB data ([0..1] for floats or [0..255] for integers).'
658 )
659 self._A = np.clip(self._A, 0, high)
660 # Cast unsupported integer types to uint8
661 if self._A.dtype != np.uint8 and np.issubdtype(self._A.dtype,
662 np.integer):
663 self._A = self._A.astype(np.uint8)
664
665 self._imcache = None
666 self._rgbacache = None
667 self.stale = True
668
669 def set_array(self, A):
670 """

Callers 2

set_arrayMethod · 0.95
imsaveFunction · 0.45

Calls 8

hasattrFunction · 0.85
pil_to_arrayFunction · 0.85
clipMethod · 0.80
convertMethod · 0.45
minMethod · 0.45
maxMethod · 0.45
warningMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected