Chris,

Both with respect to documentation and functionality, what you are 
encountering is the historical aspect of masked arrays as a tacked-on 
part of python numeric packages, and of matplotlib.  Support and 
integration are improving, but still far from perfect.  A largely new, 
and substantially different, implementation of masked arrays has been 
transplanted into numpy since the last release.  Similarly, mpl got a 
heart transplant since the last release, and it has some implications 
for the way nans and masked arrays are handled. There is lots more room 
for fundamental work on both numpy masked arrays (e.g., moving core code 
to pyrex/cython or C to speed them up) and on mpl.

Now with respect to your particular case here, trying to plot a filled 
line with gaps: poly_between has no notion of masked arrays at present. 
  If it did, how should it behave?  At the very least, additional 
arguments are needed to specify what should happen for fill-type 
plotting with missing values.  If we can come up with a clear 
description of the behaviors that should be available, then maybe we can 
provide them in mpl.  I would be happy to fix this gap in mpl's handling 
of gappy data, but I can't make it a priority use of my time right now.

For a quick fix, it sounds like what you need is either a function to 
break up your data set into gapless chunks, each of which could be 
plotted by a call to fill, or a function (a variant of poly_between) 
that would replace the gap regions with top and bottom lines at the same 
place (the bottom level? the x-axis?) so the whole thing could be 
plotted in one call to fill, provided the patch outline is suppressed.

I seem to recall someone else with a similar need in the past few 
months, so maybe someone on the list has a ready-made solution for you.

Eric

Chris Withers wrote:
> Eric Firing wrote:
>> This is not doing what you think it is,
> 
> Indeed, I guess I was seeing nans being treated as missing values rather 
> than being masked...
> 
>> You should use numpy.masked_where(numpy.isnan(aa), aa).
> 
> I am now ;-)
> 
> However, I'm still running into problems when I try and plot the gappy 
> data on a filled line as follows:
> 
> dates = *an array of datetimes*
> values = *an array containing data values and a few nans*
> values = numpy.ma.masked_where(numpy.isnan(values),values)
> xs,ys = mlab.poly_between(dates,0,values)
> pylab.fill(xs,ys,'r')
> 
> For starters, I get this warning:
> 
> numpy\core\ma.py:609: UserWarning: Cannot automatically convert masked 
> array to numeric because data is masked in one or more locations.
> 
> ...and wherever a NaN occurs in the data, the line is plotted off the 
> top of the axes. I want it to appear at 0 if there's no data. Well, 
> ideally just not appear at all, but I'd settle for appearing at 0...
> 
> Any ideas?
> 
> cheers,
> 
> Chris
> 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to