histograms and masked arrays

Hello everybody,

First I have to say, how much I appreciate using matplotlib.

But there are some annoyances. One I stumbled over recently is that histograms
don't deal with masked arrays properly.

For example:

from numpy import *
from pylab import *

bins = arange(21)
data_masked = ma.masked_values(bins,10)
hist(data_masked,bins)
show()

This example produces (with maplotlib-0.90.0, numpy-1.0) this message:
/usr/lib/python2.4/site-packages/numpy/core/ma.py:604: UserWarning: Cannot
automatically convert masked array to numeric because data
    is masked in one or more locations.
  warnings.warn("Cannot automatically convert masked array to "\

But it shows a histogram with one count per bin although data_masked[10] should
not be counted.

When I'm trying "plot(bins,data_masked)", data_masked[10] is left out as expected.

Am I missing something or are histograms not (yet) suited for handling masked
arrays?

Best regards,

Peter Melchior

Peter Melchior wrote:

Hello everybody,

First I have to say, how much I appreciate using matplotlib.

But there are some annoyances. One I stumbled over recently is that histograms
don't deal with masked arrays properly.

Fixed now in svn.

If you don't want to install from svn, use

hist(data_masked.compressed(), bins)

Eric

···

For example:

from numpy import *
from pylab import *

bins = arange(21)
data_masked = ma.masked_values(bins,10)
hist(data_masked,bins)
show()

This example produces (with maplotlib-0.90.0, numpy-1.0) this message:
/usr/lib/python2.4/site-packages/numpy/core/ma.py:604: UserWarning: Cannot
automatically convert masked array to numeric because data
    is masked in one or more locations.
  warnings.warn("Cannot automatically convert masked array to "\

But it shows a histogram with one count per bin although data_masked[10] should
not be counted.

When I'm trying "plot(bins,data_masked)", data_masked[10] is left out as expected.

Am I missing something or are histograms not (yet) suited for handling masked
arrays?

Best regards,

Peter Melchior

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options