hist() and masked_array

Hi there,

I just noticed today that when I call hist() on a masked_array, also those
values which are masked out are displayed (with their fill_value). Is that
really the desired behaviour?

I'm working in an environment where we're mostly using masked_array, but
also sometimes the 'normal' ndarray. So I would need to do something like

try:
  data = data.compressed()
except:
  pass
hist(data)

all the time ... Is there any easier solution?

Cheers,

Andreas.

Unfortunately, these lines in Axes.hist():

            # TODO: support masked arrays;
            x = np.asarray(x)

say it all. I think changing to asanyarray() should work (I'm not sure
what, if anything, this would break), but there's no way for you to
get this behavior without editing your local copy of axes.py.

Ryan

···

On Thu, Jun 17, 2010 at 10:52 AM, Andreas Hilboll <lists@...3067...> wrote:

Hi there,

I just noticed today that when I call hist() on a masked_array, also those
values which are masked out are displayed (with their fill_value). Is that
really the desired behaviour?

I'm working in an environment where we're mostly using masked_array, but
also sometimes the 'normal' ndarray. So I would need to do something like

try:
data = data.compressed()
except:
pass
hist(data)

all the time ... Is there any easier solution?

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Hi there,

I just noticed today that when I call hist() on a masked_array, also those
values which are masked out are displayed (with their fill_value). Is that
really the desired behaviour?

I'm working in an environment where we're mostly using masked_array, but
also sometimes the 'normal' ndarray. So I would need to do something like

try:
  data = data.compressed()
except:
  pass
hist(data)

all the time ... Is there any easier solution?

Unfortunately, these lines in Axes.hist():

             # TODO: support masked arrays;
             x = np.asarray(x)

say it all. I think changing to asanyarray() should work (I'm not sure
what, if anything, this would break), but there's no way for you to
get this behavior without editing your local copy of axes.py.

It takes considerably more than that. Nothing terribly difficult, but more than a couple lines.

Eric

···

On 06/17/2010 05:52 AM, Ryan May wrote:

On Thu, Jun 17, 2010 at 10:52 AM, Andreas Hilboll<lists@...3067...> wrote:

Ryan