Generate a PNG representation of the BivarColormap.
(self)
| 2118 | return new_cmap |
| 2119 | |
| 2120 | def _repr_png_(self): |
| 2121 | """Generate a PNG representation of the BivarColormap.""" |
| 2122 | if not self._isinit: |
| 2123 | self._init() |
| 2124 | pixels = self.lut |
| 2125 | if pixels.shape[0] < _BIVAR_REPR_PNG_SIZE: |
| 2126 | pixels = np.repeat(pixels, |
| 2127 | repeats=_BIVAR_REPR_PNG_SIZE//pixels.shape[0], |
| 2128 | axis=0)[:256, :] |
| 2129 | if pixels.shape[1] < _BIVAR_REPR_PNG_SIZE: |
| 2130 | pixels = np.repeat(pixels, |
| 2131 | repeats=_BIVAR_REPR_PNG_SIZE//pixels.shape[1], |
| 2132 | axis=1)[:, :256] |
| 2133 | pixels = (pixels[::-1, :, :] * 255).astype(np.uint8) |
| 2134 | png_bytes = io.BytesIO() |
| 2135 | title = self.name + ' BivarColormap' |
| 2136 | author = f'Matplotlib v{mpl.__version__}, https://matplotlib.org' |
| 2137 | pnginfo = PngInfo() |
| 2138 | pnginfo.add_text('Title', title) |
| 2139 | pnginfo.add_text('Description', title) |
| 2140 | pnginfo.add_text('Author', author) |
| 2141 | pnginfo.add_text('Software', author) |
| 2142 | Image.fromarray(pixels).save(png_bytes, format='png', pnginfo=pnginfo) |
| 2143 | return png_bytes.getvalue() |
| 2144 | |
| 2145 | def _repr_html_(self): |
| 2146 | """Generate an HTML representation of the Colormap.""" |
no test coverage detected