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

Method __call__

lib/matplotlib/colors.py:3275–3315  ·  view source on GitHub ↗

This method behaves similarly to `.Normalize.__call__`, except that it returns integers or arrays of int16.

(self, value, clip=None)

Source from the content-addressed store, hash-verified

3273 "number of bins")
3274
3275 def __call__(self, value, clip=None):
3276 """
3277 This method behaves similarly to `.Normalize.__call__`, except that it
3278 returns integers or arrays of int16.
3279 """
3280 if clip is None:
3281 clip = self.clip
3282
3283 xx, is_scalar = self.process_value(value)
3284 mask = np.ma.getmaskarray(xx)
3285 # Fill masked values a value above the upper boundary
3286 xx = np.atleast_1d(xx.filled(self.vmax + 1))
3287 if clip:
3288 np.clip(xx, self.vmin, self.vmax, out=xx)
3289 max_col = self.Ncmap - 1
3290 else:
3291 max_col = self.Ncmap
3292 # this gives us the bins in the lookup table in the range
3293 # [0, _n_regions - 1] (the offset is set in the init)
3294 iret = np.digitize(xx, self.boundaries) - 1 + self._offset
3295 # if we have more colors than regions, stretch the region
3296 # index computed above to full range of the color bins. This
3297 # will make use of the full range (but skip some of the colors
3298 # in the middle) such that the first region is mapped to the
3299 # first color and the last region is mapped to the last color.
3300 if self.Ncmap > self._n_regions:
3301 if self._n_regions == 1:
3302 # special case the 1 region case, pick the middle color
3303 iret[iret == 0] = (self.Ncmap - 1) // 2
3304 else:
3305 # otherwise linearly remap the values from the region index
3306 # to the color index spaces
3307 iret = (self.Ncmap - 1) / (self._n_regions - 1) * iret
3308 # cast to 16bit integers in all cases
3309 iret = iret.astype(np.int16)
3310 iret[xx < self.vmin] = -1
3311 iret[xx >= self.vmax] = max_col
3312 ret = np.ma.array(iret, mask=mask)
3313 if is_scalar:
3314 ret = int(ret[0]) # assume python scalar
3315 return ret
3316
3317 def inverse(self, value):
3318 """

Callers

nothing calls this directly

Calls 2

process_valueMethod · 0.80
clipMethod · 0.45

Tested by

no test coverage detected