| 780 | |
| 781 | |
| 782 | def 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 | |
| 806 | def test_axesimage_setdata(): |