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

Method to_rgba

lib/matplotlib/colorizer.py:108–147  ·  view source on GitHub ↗

Return a normalized RGBA array corresponding to *x*. In the normal case, *x* is a 1D or 2D sequence of scalars, and the corresponding `~numpy.ndarray` of RGBA values will be returned, based on the norm and colormap set for this Colorizer. There is one speci

(self, x, alpha=None, bytes=False, norm=True)

Source from the content-addressed store, hash-verified

106 self.changed()
107
108 def to_rgba(self, x, alpha=None, bytes=False, norm=True):
109 """
110 Return a normalized RGBA array corresponding to *x*.
111
112 In the normal case, *x* is a 1D or 2D sequence of scalars, and
113 the corresponding `~numpy.ndarray` of RGBA values will be returned,
114 based on the norm and colormap set for this Colorizer.
115
116 There is one special case, for handling images that are already
117 RGB or RGBA, such as might have been read from an image file.
118 If *x* is an `~numpy.ndarray` with 3 dimensions,
119 and the last dimension is either 3 or 4, then it will be
120 treated as an RGB or RGBA array, and no mapping will be done.
121 The array can be `~numpy.uint8`, or it can be floats with
122 values in the 0-1 range; otherwise a ValueError will be raised.
123 Any NaNs or masked elements will be set to 0 alpha.
124 If the last dimension is 3, the *alpha* kwarg (defaulting to 1)
125 will be used to fill in the transparency. If the last dimension
126 is 4, the *alpha* kwarg is ignored; it does not
127 replace the preexisting alpha. A ValueError will be raised
128 if the third dimension is other than 3 or 4.
129
130 In either case, if *bytes* is *False* (default), the RGBA
131 array will be floats in the 0-1 range; if it is *True*,
132 the returned RGBA array will be `~numpy.uint8` in the 0 to 255 range.
133
134 If norm is False, no normalization of the input data is
135 performed, and it is assumed to be in the range (0-1).
136
137 """
138 # First check for special case, image input:
139 if isinstance(x, np.ndarray) and x.ndim == 3:
140 return self._pass_image_data(x, alpha, bytes, norm)
141
142 # Otherwise run norm -> colormap pipeline
143 x = ma.asarray(x)
144 if norm:
145 x = self.norm(x)
146 rgba = self.cmap(x, alpha=alpha, bytes=bytes)
147 return rgba
148
149 @staticmethod
150 def _pass_image_data(x, alpha=None, bytes=False, norm=True):

Callers 15

imsaveFunction · 0.95
plot_surfaceMethod · 0.45
plot_trisurfMethod · 0.45
set_pane_colorMethod · 0.45
drawMethod · 0.45
drawMethod · 0.45
_make_imageMethod · 0.45
write_pngMethod · 0.45
make_imageMethod · 0.45
make_imageMethod · 0.45

Calls 3

_pass_image_dataMethod · 0.95
normMethod · 0.95
cmapMethod · 0.95