Skip to content

Commit 22c4a19

Browse files
committed
Added a test for imsave
1 parent 70358ac commit 22c4a19

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/matplotlib/tests/test_image.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ def test_imsave():
128128

129129
assert_array_equal(arr_dpi1, arr_dpi100)
130130

131+
def test_imsave_color_alpha():
132+
# The goal is to test that imsave will accept arrays with ndim=3 where
133+
# the third dimension is color and alpha without raising any exceptions
134+
from numpy import random
135+
random.seed(1)
136+
data = random.rand(256, 128, 4)
137+
138+
buff = io.BytesIO()
139+
plt.imsave(buff, data)
140+
141+
buff.seek(0)
142+
arr_buf = plt.imread(buff)
143+
144+
assert arr_buf.shape == data.shape
145+
146+
# Unfortunately, the AGG process "flattens" the RGBA data
147+
# into an equivalent RGB data with no transparency. So we
148+
# Can't directly compare the arrays like we could in some
149+
# other imsave tests.
150+
131151
@image_comparison(baseline_images=['image_clip'])
132152
def test_image_clip():
133153
from math import pi

0 commit comments

Comments
 (0)