Skip to content

Commit ea3c842

Browse files
committed
TST: Add test for mask + over + under in imshow
1 parent 50e33f5 commit ea3c842

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed
Loading

lib/matplotlib/tests/test_image.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
from numpy.testing import (
2525
assert_array_equal, assert_array_almost_equal, assert_allclose)
2626
from matplotlib.testing.noseclasses import KnownFailureTest
27-
28-
27+
from copy import copy
28+
from numpy import ma
29+
import matplotlib.colors as colors
30+
import matplotlib.pyplot as plt
31+
import matplotlib.mlab as mlab
32+
import numpy as np
2933

3034
import nose
3135

@@ -658,6 +662,40 @@ def test_image_preserve_size2():
658662
np.identity(n, bool)[::-1])
659663

660664

665+
@image_comparison(baseline_images=['mask_image_over_under'],
666+
remove_text=True, extensions=['png'])
667+
def test_mask_image_over_under():
668+
delta = 0.025
669+
x = y = np.arange(-3.0, 3.0, delta)
670+
X, Y = np.meshgrid(x, y)
671+
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
672+
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
673+
Z = 10*(Z2 - Z1) # difference of Gaussians
674+
675+
palette = copy(plt.cm.gray)
676+
palette.set_over('r', 1.0)
677+
palette.set_under('g', 1.0)
678+
palette.set_bad('b', 1.0)
679+
Zm = ma.masked_where(Z > 1.2, Z)
680+
fig, (ax1, ax2) = plt.subplots(1, 2)
681+
im = ax1.imshow(Zm, interpolation='bilinear',
682+
cmap=palette,
683+
norm=colors.Normalize(vmin=-1.0, vmax=1.0, clip=False),
684+
origin='lower', extent=[-3, 3, -3, 3])
685+
ax1.set_title('Green=low, Red=high, Blue=bad')
686+
fig.colorbar(im, extend='both', orientation='horizontal',
687+
ax=ax1, aspect=10)
688+
689+
im = ax2.imshow(Zm, interpolation='nearest',
690+
cmap=palette,
691+
norm=colors.BoundaryNorm([-1, -0.5, -0.2, 0, 0.2, 0.5, 1],
692+
ncolors=256, clip=False),
693+
origin='lower', extent=[-3, 3, -3, 3])
694+
ax2.set_title('With BoundaryNorm')
695+
fig.colorbar(im, extend='both', spacing='proportional',
696+
orientation='horizontal', ax=ax2, aspect=10)
697+
698+
661699
@image_comparison(baseline_images=['mask_image'],
662700
remove_text=True)
663701
def test_mask_image():

0 commit comments

Comments
 (0)