Generate a PNG representation of the Colormap.
(self)
| 1653 | return self._combination_mode |
| 1654 | |
| 1655 | def _repr_png_(self): |
| 1656 | """Generate a PNG representation of the Colormap.""" |
| 1657 | X = np.tile(np.linspace(0, 1, _REPR_PNG_SIZE[0]), |
| 1658 | (_REPR_PNG_SIZE[1], 1)) |
| 1659 | pixels = np.zeros((_REPR_PNG_SIZE[1]*len(self), _REPR_PNG_SIZE[0], 4), |
| 1660 | dtype=np.uint8) |
| 1661 | for i, c in enumerate(self): |
| 1662 | pixels[i*_REPR_PNG_SIZE[1]:(i+1)*_REPR_PNG_SIZE[1], :] = c(X, bytes=True) |
| 1663 | png_bytes = io.BytesIO() |
| 1664 | title = self.name + ' multivariate colormap' |
| 1665 | author = f'Matplotlib v{mpl.__version__}, https://matplotlib.org' |
| 1666 | pnginfo = PngInfo() |
| 1667 | pnginfo.add_text('Title', title) |
| 1668 | pnginfo.add_text('Description', title) |
| 1669 | pnginfo.add_text('Author', author) |
| 1670 | pnginfo.add_text('Software', author) |
| 1671 | Image.fromarray(pixels).save(png_bytes, format='png', pnginfo=pnginfo) |
| 1672 | return png_bytes.getvalue() |
| 1673 | |
| 1674 | def _repr_html_(self): |
| 1675 | """Generate an HTML representation of the MultivarColormap.""" |