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

Method _repr_png_

lib/matplotlib/colors.py:2120–2143  ·  view source on GitHub ↗

Generate a PNG representation of the BivarColormap.

(self)

Source from the content-addressed store, hash-verified

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."""

Callers 1

_repr_html_Method · 0.95

Calls 2

_initMethod · 0.95
saveMethod · 0.80

Tested by

no test coverage detected