Lines drawn across NaN data

I'm having trouble plotting data with NaN values. My plot has lines and
markers and usually both are skipped for NaN values. But when I have
more than 127 data a line is drawn from the last non-NaN to the next.

I read somewhere about a similar issue (maybe here? sorry I can't find
it just now), it seems like it has to do with some optimization
performed for large datasets and the use if lineto instead of moveto or
something like that. It was supposed to be fixed in 0.98.2 but I'm using
0.98.3 from Benjamin Drung's PPA (http://ppa.launchpad.net/bdrung).

This code shows the difference between plotting 127 and 128 data (look
at the left of each figure):

import pylab as pl
x = pl.random(128)
x[4:7] = pl.NaN
y = x[:-1]
pl.figure(1)
pl.plot(x, '-o')
pl.grid(True)
pl.figure(2)
pl.plot(y, '-o')
pl.grid(True)
pl.show()

Is this a known issue? Is there any workaround?

Thanks

Goyo

I worked around this using masked arrays from numpy.ma.

import numpy.ma as ma

import pylab as pl

import numpy as np

x = …
x = ma.masked_where(np.isnan(x), x)

pl.plot(x)

pl.show()

···

On Wed, Sep 17, 2008 at 6:36 PM, Goyo <goyodiaz@…287…> wrote:

I’m having trouble plotting data with NaN values. My plot has lines and

markers and usually both are skipped for NaN values. But when I have

more than 127 data a line is drawn from the last non-NaN to the next.

I read somewhere about a similar issue (maybe here? sorry I can’t find

it just now), it seems like it has to do with some optimization

performed for large datasets and the use if lineto instead of moveto or

something like that. It was supposed to be fixed in 0.98.2 but I’m using

0.98.3 from Benjamin Drung’s PPA (http://ppa.launchpad.net/bdrung).

This code shows the difference between plotting 127 and 128 data (look

at the left of each figure):

import pylab as pl

x = pl.random(128)

x[4:7] = pl.NaN

y = x[:-1]

pl.figure(1)

pl.plot(x, ‘-o’)

pl.grid(True)

pl.figure(2)

pl.plot(y, ‘-o’)

pl.grid(True)

pl.show()

Is this a known issue? Is there any workaround?

Thanks

Goyo


This SF.Net email is sponsored by the Moblin Your Move Developer’s challenge

Build the coolest Linux based applications with Moblin SDK & win great prizes

Grand prize is a trip for two to an Open Source event anywhere in the world

http://moblin-contest.org/redirect.php?banner_id=100&url=/


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Proper NaN handling has been a long and winding road.

This particuar bug you're running into was fixed about a week *after* the 0.98.3 release. Here's the patch:

So SVN trunk currently works. The patch against 0.98.3 is non-trivial -- there were actually many changes throughout the code to make all this work, so there isn't an easy workaround, and in any case requires a recompile.

If you can build from SVN, that's what I would suggest -- otherwise wait for the 0.98.4 release (I don't believe we have an ETA on that, yet).

Cheers,
Mike

Goyo wrote:

···

I'm having trouble plotting data with NaN values. My plot has lines and
markers and usually both are skipped for NaN values. But when I have
more than 127 data a line is drawn from the last non-NaN to the next.

I read somewhere about a similar issue (maybe here? sorry I can't find
it just now), it seems like it has to do with some optimization
performed for large datasets and the use if lineto instead of moveto or
something like that. It was supposed to be fixed in 0.98.2 but I'm using
0.98.3 from Benjamin Drung's PPA (Benjamin Drung in Launchpad).

This code shows the difference between plotting 127 and 128 data (look
at the left of each figure):

import pylab as pl
x = pl.random(128)
x[4:7] = pl.NaN
y = x[:-1]
pl.figure(1)
pl.plot(x, '-o')
pl.grid(True)
pl.figure(2)
pl.plot(y, '-o')
pl.grid(True)
pl.show()

Is this a known issue? Is there any workaround?

Thanks

Goyo

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Tanks, Michael. Maybe I'll try to build from SVN this weekend.

Goyo

···

El jue, 18-09-2008 a las 09:31 -0400, Michael Droettboom escribió:

Proper NaN handling has been a long and winding road.

This particuar bug you're running into was fixed about a week *after*
the 0.98.3 release. Here's the patch:

matplotlib download | SourceForge.net

So SVN trunk currently works. The patch against 0.98.3 is non-trivial
-- there were actually many changes throughout the code to make all this
work, so there isn't an easy workaround, and in any case requires a
recompile.

If you can build from SVN, that's what I would suggest -- otherwise wait
for the 0.98.4 release (I don't believe we have an ETA on that, yet).

Cheers,
Mike

Goyo wrote:
> I'm having trouble plotting data with NaN values. My plot has lines and
> markers and usually both are skipped for NaN values. But when I have
> more than 127 data a line is drawn from the last non-NaN to the next.
>
> I read somewhere about a similar issue (maybe here? sorry I can't find
> it just now), it seems like it has to do with some optimization
> performed for large datasets and the use if lineto instead of moveto or
> something like that. It was supposed to be fixed in 0.98.2 but I'm using
> 0.98.3 from Benjamin Drung's PPA (Benjamin Drung in Launchpad).
>
> This code shows the difference between plotting 127 and 128 data (look
> at the left of each figure):
>
> import pylab as pl
> x = pl.random(128)
> x[4:7] = pl.NaN
> y = x[:-1]
> pl.figure(1)
> pl.plot(x, '-o')
> pl.grid(True)
> pl.figure(2)
> pl.plot(y, '-o')
> pl.grid(True)
> pl.show()
>
> Is this a known issue? Is there any workaround?
>
> Thanks
>
> Goyo
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> matplotlib-users List Signup and Options
>