|
24 | 24 | from numpy.testing import (
|
25 | 25 | assert_array_equal, assert_array_almost_equal, assert_allclose)
|
26 | 26 | 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 |
29 | 33 |
|
30 | 34 | import nose
|
31 | 35 |
|
@@ -658,6 +662,40 @@ def test_image_preserve_size2():
|
658 | 662 | np.identity(n, bool)[::-1])
|
659 | 663 |
|
660 | 664 |
|
| 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 | + |
661 | 699 | @image_comparison(baseline_images=['mask_image'],
|
662 | 700 | remove_text=True)
|
663 | 701 | def test_mask_image():
|
|
0 commit comments