[SciPy-User] pylab

Joshua Holbrook josh.holbrook@gmail....
Mon Jul 19 18:24:28 CDT 2010

2010/7/19 பழநி சே <palaniappan.chetty@gmail.com>:
> hi,
> I have a question about pylab/matplotlib, I am interested in plots and
> I want to know if I can have some data points in a data sets missing
> but still create a plot using pylab? For example (assuming all modules
> have been imported)
>>x = [1,2,3,4]
> works fine. But what if I have one or more data points missing in my y
> data set? like this
>>x = [1,2,3,4]
>>y=[10,20, ,40]
> I know that I cannot have an empty element in my list and this does not work
> Thanks
> --
> Palani
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

Hey Palani,

I'm not extremely familiar with matplotlib, but my experience tells me
that, while MPL itself wouldn't really have any nice way to do this,
that you could import a dataset and use python/numpy to clean it up.
For example, you could maybe use filter() and zip()  (zip's my
favorite toy), maybe like this:

    In [30]: x
    Out[30]: [0, 1, 2, 3, 4]

    In [31]: y
    Out[31]: [0, 1, 4, None, 16]

    In [32]: zip(*filter(lambda x: x[1] != None, zip(x,y)))
    Out[32]: [(0, 1, 2, 4), (0, 1, 4, 16)]

and then you could do plot(_[0],_[1]).  Alternately, and this would
probably be worth investigating for bigger datasets, you could maybe
use masked arrays
to do something similar in spirit.

Hope that helped!


More information about the SciPy-User mailing list