[SciPy-user] How To Plot List with None Values?

eric eric at enthought.com
Mon May 20 23:11:28 EDT 2002


One solution is to split the array up into the segments between the None values
and just plot these with gaps in spots that had None values.  You could modify
the code to connect the segments if that is preferable.

Hope that helps,

eric

--------------------

>>> import gui_thread
>>> import tp
>>> tp.plt_noneless([None,1,2,None,4,5,None])

--------------------
# tp.py
from Numeric import *

def noneless(a):
    a= asarray(a)
    ind = compress(a==None,arange(len(a)))
    ind = concatenate(([-1],ind,[len(a)]))
    pairs = zip(ind[:-1],ind[1:])

    segments = []
    for low,hi in pairs:
        sub_a = a[low+1:hi].astype(Float64)
        if sub_a:
            segments.append([arange(low+1,hi),sub_a])
    return segments

def plt_noneless(a,fmt ='b-'):
    from scipy import plt
    segments = noneless(a)
    plt.figure()
    plt.hold('on')
    for x,y in segments:
        plt.plot(x,y,fmt)
    plt.hold('off')



----- Original Message -----
From: "ring zero" <ringzero at spl.at>
To: <scipy-user at scipy.net>
Sent: Monday, May 20, 2002 7:33 PM
Subject: [SciPy-user] How To Plot List with None Values?


> Hello Everyone:
>
> Please forgive me if this question has been asked and answered.  I'm new to
scipy and scientific programming in general and I couldn't find an answer for
this in the list archives.
>
> I have multiple lists that I'd like to show on a single plot.  The first list
is just a bunch of floats, in the form of:
>
> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
>
> My problem is with my secondary lists, which are all in the form of:
>
> [None, None, 3.5, 4.5, 5.5, 6.5]
>
> Each of these secondary lists may have one or more None values at the
beginning.  My first naive approach was to replace each None with 0.0, and that
worked, but my plot scale was skewed to the point of uselessness.
>
> Can anyone point me to a solution?  I'd like each secondary list to plot right
aligned with the first, and with the initial None values dropped off.
>
> Any help is appreciated.
>
> rz
>
> p.s., thanks for scipy, it rocks.
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>





More information about the SciPy-User mailing list