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

Function test_indexed_image

lib/matplotlib/tests/test_backend_pdf.py:100–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98
99
100def test_indexed_image():
101 # An image with low color count should compress to a palette-indexed format.
102 pikepdf = pytest.importorskip('pikepdf')
103
104 data = np.zeros((256, 1, 3), dtype=np.uint8)
105 data[:, 0, 0] = np.arange(256) # Maximum unique colours for an indexed image.
106
107 rcParams['pdf.compression'] = True
108 fig = plt.figure()
109 fig.figimage(data, resize=True)
110 buf = io.BytesIO()
111 fig.savefig(buf, format='pdf', dpi='figure')
112
113 with pikepdf.Pdf.open(buf) as pdf:
114 page, = pdf.pages
115 image, = page.images.values()
116 pdf_image = pikepdf.PdfImage(image)
117 assert pdf_image.indexed
118 pil_image = pdf_image.as_pil_image()
119 rgb = np.asarray(pil_image.convert('RGB'))
120
121 np.testing.assert_array_equal(data, rgb)
122
123
124def test_savefig_metadata(monkeypatch):

Callers

nothing calls this directly

Calls 6

figureMethod · 0.80
figimageMethod · 0.80
valuesMethod · 0.80
savefigMethod · 0.45
openMethod · 0.45
convertMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…