plot with nans

Alan,

Is the default handling of nan by plot the "right" one?
I am accustomed (from GAUSS) to missing values being
treated as "gaps".
E.g.,
    x=[nan,2,3,4,5]
    plot(x)
fails completely. I expect the last 4 numbers to be plotted.
    x=[1,2,nan,4,5]
    plot(x)
plots a single line. I expect two segments and a gap.

Slightly modifying a reply to a similar question not long ago:

At present, you need to use masked arrays instead of NaN. NaN is not uniformly supported in Python and numerix, but masked arrays, in both numarray and Numeric, can accomplish the same thing and more. See masked_demo.py in the mpl examples subdirectory, and see http://stsdas.stsci.edu/numarray/numarray-1.3.html/module-numarray.ma.html
for an explanation of masked arrays.

Numeric is in the midst of a major revision (including renaming), which I think will include support of NaNs similar to that in numarray. When this new version becomes common, then it may be both possible and desirable for matplotlib to handle NaNs as smoothly as Matlab, Octave, and evidently Gauss do.

Eric

    x=[1,2,nan,4,5] plot(x) plots a single line.
    I expect two segments and a gap.

Slightly modifying a reply to a similar question not long ago:
At present, you need to use masked arrays instead of NaN.

So if I use masked arrays,
I should get two segments and a gap in the above case?

I'm not familiar with masked arrays.
Sounds like I'll have to learn about them.

But I still feel something is missing from this discussion.
Would it be odd/hard for plot() to have an option that says,
effectively, mask NaNs so that the expected behavior results?

Thanks,
Alan

···

On Mon, 11 Jul 2005, Eric Firing apparently wrote: