>>> import numarray as N
>>> from numarray.ieeespecial import isnan, nan
>>> import numarray.ma as ma
>>> a = N.array([1, 2, nan, 3, 4])
>>> b = ma.masked_where(isnan(a), a)
Now you can plot b and it will have a gap in the middle.
I tried it as described above but plotting with pylab.plot results in an error message:
MAError: Cannot automatically convert masked array to Numeric because data
is masked in one or more locations.
Am I missing something?
The problem is that you need to use numarray, not Numeric, as your numerix choice. In your matplotlibrc file, use
numerix : numarray # Numeric or numarray
instead of the default, which is Numeric.
Unfortunately, although there is some partial compatibility between Numeric and numarray, it does not extend to one being able to read masked arrays from the other, so you need to use one or the other consistently. And if you want to work with nans, then numarray is the one you need to use.