8000 Use check_figures_equal. · matplotlib/matplotlib@fc64a19 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc64a19

Browse files
committed
Use check_figures_equal.
1 parent 95a4b41 commit fc64a19

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/matplotlib/image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ def set_alpha(self, alpha):
293293
self._imcache = None
294294

295295
def _get_scalar_alpha(self):
296-
return self._alpha if np.ndim(self._alpha) == 0 else 1.0
296+
return 1.0 if self._alpha is None or np.ndim(self._alpha) > 0 \
297+
else self._alpha
297298

298299
def changed(self):
299300
"""

lib/matplotlib/tests/test_image.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,3 +1118,22 @@ def test_image_cursor_formatting():
11181118

11191119
data = np.nan
11201120
assert im.format_cursor_data(data) == '[nan]'
1121+
1122+
1123+
@check_figures_equal()
1124+
def test_image_array_alpha(fig_test, fig_ref):
1125+
'''per-pixel alpha channel test'''
1126+
x = np.linspace(0, 1)
1127+
xx, yy = np.meshgrid(x, x)
1128+
1129+
zz = np.exp(- 3 * ((xx - 0.5) ** 2) + (yy - 0.7 ** 2))
1130+
alpha = zz / zz.max()
1131+
1132+
cmap = plt.get_cmap('viridis')
1133+
ax = fig_test.add_subplot(111)
1134+
ax.imshow(zz, alpha=alpha, cmap=cmap, interpolation='nearest')
1135+
1136+
ax = fig_ref.add_subplot(111)
1137+
rgba = cmap(colors.Normalize()(zz))
1138+
rgba[..., -1] = alpha
1139+
ax.imshow(rgba, interpolation='nearest')

0 commit comments

Comments
 (0)
0