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

Skip to content

Commit 6a2f896

Browse files
committed
Move delete_masked_points() from axes.py to cbook.py so that it's available to more places.
svn path=/trunk/matplotlib/; revision=5794
1 parent 7e1b99b commit 6a2f896

2 files changed

Lines changed: 43 additions & 43 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import division, generators
2-
import math, sys, warnings, datetime, new, types
2+
import math, sys, warnings, datetime, new
33

44
import numpy as np
55
from numpy import ma
@@ -31,45 +31,6 @@
3131
is_string_like = cbook.is_string_like
3232

3333

34-
def delete_masked_points(*args):
35-
"""
36-
Find all masked points in a set of arguments, and return
37-
the arguments with only the unmasked points remaining.
38-
39-
This will also delete any points that are not finite (nan or inf).
40-
41-
The overall mask is calculated from any masks that are present.
42-
If a mask is found, any argument that does not have the same
43-
dimensions is left unchanged; therefore the argument list may
44-
include arguments that can take string or array values, for
45-
example.
46-
47-
Array arguments must have the same length; masked arguments must
48-
be one-dimensional.
49-
50-
Written as a helper for scatter, but may be more generally
51-
useful.
52-
"""
53-
masks = [ma.getmaskarray(x) for x in args if hasattr(x, 'mask')]
54-
isfinite = [np.isfinite(x) for x in args]
55-
masks.extend( [~x for x in isfinite if not isinstance(x,types.NotImplementedType)] )
56-
if len(masks) == 0:
57-
return args
58-
mask = reduce(np.logical_or, masks)
59-
margs = []
60-
for x in args:
61-
if (not is_string_like(x)
62-
and iterable(x)
63-
and len(x) == len(mask)):
64-
if (hasattr(x, 'get_compressed_copy')):
65-
compressed_x = x.get_compressed_copy(mask)
66-
else:
67-
compressed_x = ma.masked_array(x, mask=mask).compressed()
68-
margs.append(compressed_x)
69-
else:
70-
margs.append(x)
71-
return margs
72-
7334
def _process_plot_format(fmt):
7435
"""
7536
Process a matlab(TM) style color/line style format string. Return a
@@ -4827,7 +4788,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
48274788

48284789
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
48294790

4830-
x, y, s, c = delete_masked_points(x, y, s, c)
4791+
x, y, s, c = cbook.delete_masked_points(x, y, s, c)
48314792

48324793
# The inherent ambiguity is resolved in favor of color
48334794
# mapping, not interpretation as rgb or rgba.
@@ -5091,7 +5052,7 @@ def hexbin(self, x, y, gridsize = 100, bins = None,
50915052

50925053
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
50935054

5094-
x, y = delete_masked_points(x, y)
5055+
x, y = cbook.delete_masked_points(x, y)
50955056

50965057
# Set the size of the hexagon grid
50975058
if iterable(gridsize):

lib/matplotlib/cbook.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from the Python Cookbook -- hence the name cbook
44
"""
55
from __future__ import generators
6-
import re, os, errno, sys, StringIO, traceback, locale, threading
6+
import re, os, errno, sys, StringIO, traceback, locale, threading, types
77
import time, datetime
88
import numpy as np
9+
from numpy import ma
910
from weakref import ref
1011

1112
major, minor1, minor2, s, tmp = sys.version_info
@@ -1165,6 +1166,44 @@ def recursive_remove(path):
11651166
else:
11661167
os.remove(path)
11671168

1169+
def delete_masked_points(*args):
1170+
"""
1171+
Find all masked points in a set of arguments, and return
1172+
the arguments with only the unmasked points remaining.
1173+
1174+
This will also delete any points that are not finite (nan or inf).
1175+
1176+
The overall mask is calculated from any masks that are present.
1177+
If a mask is found, any argument that does not have the same
1178+
dimensions is left unchanged; therefore the argument list may
1179+
include arguments that can take string or array values, for
1180+
example.
1181+
1182+
Array arguments must have the same length; masked arguments must
1183+
be one-dimensional.
1184+
1185+
Written as a helper for scatter, but may be more generally
1186+
useful.
1187+
"""
1188+
masks = [ma.getmaskarray(x) for x in args if hasattr(x, 'mask')]
1189+
isfinite = [np.isfinite(x) for x in args]
1190+
masks.extend( [~x for x in isfinite if not isinstance(x,types.NotImplementedType)] )
1191+
if len(masks) == 0:
1192+
return args
1193+
mask = reduce(np.logical_or, masks)
1194+
margs = []
1195+
for x in args:
1196+
if (not is_string_like(x)
1197+
and iterable(x)
1198+
and len(x) == len(mask)):
1199+
if (hasattr(x, 'get_compressed_copy')):
1200+
compressed_x = x.get_compressed_copy(mask)
1201+
else:
1202+
compressed_x = ma.masked_array(x, mask=mask).compressed()
1203+
margs.append(compressed_x)
1204+
else:
1205+
margs.append(x)
1206+
return margs
11681207

11691208

11701209
# a dict to cross-map linestyle arguments

0 commit comments

Comments
 (0)