diff --git a/build.out b/build.out new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index c55f77811859..c7b814ab024a 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5869,6 +5869,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None, `~matplotlib.pyplot.imshow` expects RGB images adopting the straight (unassociated) alpha representation. """ + im = mimage.AxesImage(self, cmap=cmap, norm=norm, colorizer=colorizer, interpolation=interpolation, origin=origin, extent=extent, filternorm=filternorm, diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 53ea452f4c84..2466ae9eaa0f 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -28,6 +28,7 @@ Affine2D, BboxBase, Bbox, BboxTransform, BboxTransformTo, IdentityTransform, TransformedBbox) + _log = logging.getLogger(__name__) # map interpolation strings to module constants @@ -1093,6 +1094,7 @@ def set_data(self, x, y, A): """ Set the grid for the pixel centers, and the pixel values. + Parameters ---------- x, y : 1D array-like @@ -1582,6 +1584,10 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, _api.check_in_list(('upper', 'lower'), origin=origin) if origin == "lower": arr = arr[::-1] + + if (isinstance(arr, list)): + arr = np.asarray(arr, dtype=np.uint8) + if (isinstance(arr, memoryview) and arr.format == "B" and arr.ndim == 3 and arr.shape[-1] == 4): # Such an ``arr`` would also be handled fine by sm.to_rgba below @@ -1630,6 +1636,7 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, background = PIL.Image.new("RGB", pil_shape, color) background.paste(image, image) image = background + pil_kwargs.setdefault("format", format) pil_kwargs.setdefault("dpi", (dpi, dpi)) image.save(fname, **pil_kwargs) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 24a0ab929bbf..b02d005bb841 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -197,6 +197,25 @@ def test_imsave_fspath(fmt): plt.imsave(Path(os.devnull), np.array([[0, 1]]), format=fmt) +def test_imsave_python_vanilla_list(): + # Initializing RGBA data + # Instead of testing numpy array, use python list + input_img = [ + [[255, 0, 0, 1], [0, 255, 0, 1], [0, 0, 255, 1]], + [[0, 255, 0, 1], [0, 255, 0, 1], [0, 0, 0, 1]], + [[0, 0, 255, 1], [0, 0, 255, 1], [0, 0, 0, 1]] + ] + buff = io.BytesIO() + plt.imsave(buff, input_img, format="png") + buff.seek(0) + read_img = plt.imread(buff) + + # Need to multiply by 255 to adjust for normalization in imread() + read_img = (255*read_img).astype('uint8') + + assert_array_equal(np.array(input_img), read_img) + + def test_imsave_color_alpha(): # Test that imsave accept arrays with ndim=3 where the third dimension is # color and alpha without raising any exceptions, and that the data is