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

Function test_jpeg_alpha

lib/matplotlib/tests/test_image.py:782–803  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

780
781
782def test_jpeg_alpha():
783 plt.figure(figsize=(1, 1), dpi=300)
784 # Create an image that is all black, with a gradient from 0-1 in
785 # the alpha channel from left to right.
786 im = np.zeros((300, 300, 4), dtype=float)
787 im[..., 3] = np.linspace(0.0, 1.0, 300)
788
789 plt.figimage(im)
790
791 buff = io.BytesIO()
792 plt.savefig(buff, facecolor="red", format='jpg', dpi=300)
793
794 buff.seek(0)
795 image = Image.open(buff)
796
797 # If this fails, there will be only one color (all black). If this
798 # is working, we should have all 256 shades of grey represented.
799 num_colors = len(image.getcolors(256))
800 assert 175 <= num_colors <= 230
801 # The fully transparent part should be red.
802 corner_pixel = image.getpixel((0, 0))
803 assert corner_pixel == (254, 0, 0)
804
805
806def test_axesimage_setdata():

Callers

nothing calls this directly

Calls 4

figureMethod · 0.80
figimageMethod · 0.80
savefigMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…