Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6ee8fb

Browse files
committed
Contouring handles nans in Z via masking.
(The bug in filled contouring with internal masked regions remains.) svn path=/trunk/matplotlib/; revision=7005
1 parent 0e232e5 commit e6ee8fb

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

CHANGELOG

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
2009-03-20 Add AuxTransformBox in offsetbox.py to support some transformation.
2-
anchored_text.py example is enhanced and renamed
1+
2009-03-25 Make contour and contourf handle nan in their Z argument. - EF
2+
3+
2009-03-20 Add AuxTransformBox in offsetbox.py to support some transformation.
4+
anchored_text.py example is enhanced and renamed
35
(anchored_artists.py). - JJL
46

57
2009-03-20 Add "bar" connection style for annotation - JJL

examples/pylab_examples/contourf_demo.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
origin = 'lower'
44
#origin = 'upper'
55

6-
test_masking = False # There is a bug in filled contour masking.
6+
# The following controls only interior masking.
7+
test_masking = False # There is a bug in filled contour masking with
8+
# interior masks.
79

810
if test_masking:
911
# Use a coarse grid so only a few masked points are needed.
@@ -30,6 +32,18 @@
3032
Z[0,0] = 0
3133
Z = ma.array(Z, mask=badmask)
3234

35+
nr, nc = Z.shape
36+
37+
# put NaNs in one corner:
38+
Z[-nr//6:, -nc//6:] = nan
39+
# contourf will convert these to masked
40+
41+
42+
Z = ma.array(Z)
43+
# mask another corner:
44+
Z[:nr//6, :nc//6] = ma.masked
45+
46+
3347
# We are using automatic selection of contour levels;
3448
# this is usually not such a good idea, because they don't
3549
# occur on nice boundaries, but we do it here for purposes
@@ -48,7 +62,7 @@
4862
origin=origin,
4963
hold='on')
5064

51-
title('Nonsense')
65+
title('Nonsense (with 2 masked corners)')
5266
xlabel('word length anomaly')
5367
ylabel('sentence length anomaly')
5468

@@ -72,7 +86,7 @@
7286
colors = ('k',),
7387
linewidths = (3,),
7488
origin = origin)
75-
title('Listed colors')
89+
title('Listed colors (with 2 masked corners)')
7690
clabel(CS4, fmt = '%2.1f', colors = 'w', fontsize=14)
7791
colorbar(CS3)
7892

lib/matplotlib/contour.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ def _contour_args(self, *args):
756756
x,y,z = self._check_xyz(args[:3])
757757
else:
758758
raise TypeError("Too many arguments to %s; see help(%s)" % (fn,fn))
759+
z = ma.masked_invalid(z, copy=False)
759760
self.zmax = ma.maximum(z)
760761
self.zmin = ma.minimum(z)
761762
if self.logscale and self.zmin <= 0:

0 commit comments

Comments
 (0)