From: <ry...@us...> - 2008-07-20 02:59:07
|
Revision: 5794 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5794&view=rev Author: ryanmay Date: 2008-07-20 02:59:00 +0000 (Sun, 20 Jul 2008) Log Message: ----------- Move delete_masked_points() from axes.py to cbook.py so that it's available to more places. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-20 00:57:41 UTC (rev 5793) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-20 02:59:00 UTC (rev 5794) @@ -1,5 +1,5 @@ from __future__ import division, generators -import math, sys, warnings, datetime, new, types +import math, sys, warnings, datetime, new import numpy as np from numpy import ma @@ -31,45 +31,6 @@ is_string_like = cbook.is_string_like -def delete_masked_points(*args): - """ - Find all masked points in a set of arguments, and return - the arguments with only the unmasked points remaining. - - This will also delete any points that are not finite (nan or inf). - - The overall mask is calculated from any masks that are present. - If a mask is found, any argument that does not have the same - dimensions is left unchanged; therefore the argument list may - include arguments that can take string or array values, for - example. - - Array arguments must have the same length; masked arguments must - be one-dimensional. - - Written as a helper for scatter, but may be more generally - useful. - """ - masks = [ma.getmaskarray(x) for x in args if hasattr(x, 'mask')] - isfinite = [np.isfinite(x) for x in args] - masks.extend( [~x for x in isfinite if not isinstance(x,types.NotImplementedType)] ) - if len(masks) == 0: - return args - mask = reduce(np.logical_or, masks) - margs = [] - for x in args: - if (not is_string_like(x) - and iterable(x) - and len(x) == len(mask)): - if (hasattr(x, 'get_compressed_copy')): - compressed_x = x.get_compressed_copy(mask) - else: - compressed_x = ma.masked_array(x, mask=mask).compressed() - margs.append(compressed_x) - else: - margs.append(x) - return margs - def _process_plot_format(fmt): """ Process a matlab(TM) style color/line style format string. Return a @@ -4827,7 +4788,7 @@ self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) - x, y, s, c = delete_masked_points(x, y, s, c) + x, y, s, c = cbook.delete_masked_points(x, y, s, c) # The inherent ambiguity is resolved in favor of color # mapping, not interpretation as rgb or rgba. @@ -5091,7 +5052,7 @@ self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) - x, y = delete_masked_points(x, y) + x, y = cbook.delete_masked_points(x, y) # Set the size of the hexagon grid if iterable(gridsize): Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-20 00:57:41 UTC (rev 5793) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-20 02:59:00 UTC (rev 5794) @@ -3,9 +3,10 @@ from the Python Cookbook -- hence the name cbook """ from __future__ import generators -import re, os, errno, sys, StringIO, traceback, locale, threading +import re, os, errno, sys, StringIO, traceback, locale, threading, types import time, datetime import numpy as np +from numpy import ma from weakref import ref major, minor1, minor2, s, tmp = sys.version_info @@ -1165,8 +1166,46 @@ else: os.remove(path) +def delete_masked_points(*args): + """ + Find all masked points in a set of arguments, and return + the arguments with only the unmasked points remaining. + This will also delete any points that are not finite (nan or inf). + The overall mask is calculated from any masks that are present. + If a mask is found, any argument that does not have the same + dimensions is left unchanged; therefore the argument list may + include arguments that can take string or array values, for + example. + + Array arguments must have the same length; masked arguments must + be one-dimensional. + + Written as a helper for scatter, but may be more generally + useful. + """ + masks = [ma.getmaskarray(x) for x in args if hasattr(x, 'mask')] + isfinite = [np.isfinite(x) for x in args] + masks.extend( [~x for x in isfinite if not isinstance(x,types.NotImplementedType)] ) + if len(masks) == 0: + return args + mask = reduce(np.logical_or, masks) + margs = [] + for x in args: + if (not is_string_like(x) + and iterable(x) + and len(x) == len(mask)): + if (hasattr(x, 'get_compressed_copy')): + compressed_x = x.get_compressed_copy(mask) + else: + compressed_x = ma.masked_array(x, mask=mask).compressed() + margs.append(compressed_x) + else: + margs.append(x) + return margs + + # a dict to cross-map linestyle arguments _linestyles = [('-', 'solid'), ('--', 'dashed'), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |