MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _clip

Method _clip

lib/matplotlib/colors.py:2037–2091  ·  view source on GitHub ↗

For internal use when applying a BivarColormap to data. i.e. cm.ScalarMappable().to_rgba() Clips X[0] and X[1] according to 'self.shape'. X is modified in-place. Parameters ---------- X: np.array array of floats or ints to be clip

(self, X)

Source from the content-addressed store, hash-verified

2035 return self._origin
2036
2037 def _clip(self, X):
2038 """
2039 For internal use when applying a BivarColormap to data.
2040 i.e. cm.ScalarMappable().to_rgba()
2041 Clips X[0] and X[1] according to 'self.shape'.
2042 X is modified in-place.
2043
2044 Parameters
2045 ----------
2046 X: np.array
2047 array of floats or ints to be clipped
2048 shape : {'square', 'circle', 'ignore', 'circleignore'}
2049
2050 - If 'square' each variate is clipped to [0,1] independently
2051 - If 'circle' the variates are clipped radially to the center
2052 of the colormap.
2053 It is assumed that a circular mask is applied when the colormap
2054 is displayed
2055 - If 'ignore' the variates are not clipped, but instead assigned the
2056 'outside' color
2057 - If 'circleignore' a circular mask is applied, but the data is not clipped
2058 and instead assigned the 'outside' color
2059
2060 """
2061 if self.shape == 'square':
2062 for X_part, mx in zip(X, (self.N, self.M)):
2063 X_part[X_part < 0] = 0
2064 if X_part.dtype.kind == "f":
2065 X_part[X_part > 1] = 1
2066 else:
2067 X_part[X_part >= mx] = mx - 1
2068
2069 elif self.shape == 'ignore':
2070 for X_part, mx in zip(X, (self.N, self.M)):
2071 X_part[X_part < 0] = -1
2072 if X_part.dtype.kind == "f":
2073 X_part[X_part > 1] = -1
2074 else:
2075 X_part[X_part >= mx] = -1
2076
2077 elif self.shape == 'circle' or self.shape == 'circleignore':
2078 for X_part in X:
2079 if X_part.dtype.kind != "f":
2080 raise NotImplementedError(
2081 "Circular bivariate colormaps are only"
2082 " implemented for use with with floats")
2083 radii_sqr = (X[0] - 0.5)**2 + (X[1] - 0.5)**2
2084 mask_outside = radii_sqr > 0.25
2085 if self.shape == 'circle':
2086 overextend = 2 * np.sqrt(radii_sqr[mask_outside])
2087 X[0][mask_outside] = (X[0][mask_outside] - 0.5) / overextend + 0.5
2088 X[1][mask_outside] = (X[1][mask_outside] - 0.5) / overextend + 0.5
2089 else:
2090 X[0][mask_outside] = -1
2091 X[1][mask_outside] = -1
2092
2093 def __getitem__(self, item):
2094 """Creates and returns a colorbar along the selected axis"""

Callers 1

__call__Method · 0.95

Calls 1

sqrtMethod · 0.80

Tested by

no test coverage detected