Re: Plotting syntax

Discussion in 'Python' started by Oscar Benjamin, Feb 7, 2013.

  1. On 7 February 2013 09:37, Jean-Michel Pichavant <> wrote:
    > ----- Original Message -----
    >
    >> Hi Python experts,
    >> I am working with an array of data and am trying to plot several
    >> columns of data which are not continuous; i.e. I would like to plot
    >> columns 1:4 and 6:8, without plotting column 5. The syntax I am
    >> currently using is:
    >>
    >> oplot (t,d[:,0:4])
    >>

    [SNIP]
    >
    > x = x[0:4]+ x[5:8]
    > y = y[0:4]+ y[5:8]
    >
    > skips the element at index 4, meaning the fifth columns.
    > Alternatively,
    >
    > x = x[:4]+ x[5:]
    > y = y[:4]+ y[5:]
    >
    > skips the 5th element without regard for the length of the list.
    > http://docs.python.org/release/2.3.5/whatsnew/section-slices.html


    I'm guessing from the multi-dimensional slice syntax that d is a numpy
    array in which case the + operator attempts to sum the two arrays
    element-wise (resulting in an error if they are not the same shape):

    >>> from numpy import array
    >>> a = array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
    >>> a

    array([[ 1, 2, 3],
    [ 4, 5, 6],
    [ 7, 8, 9],
    [10, 11, 12]])
    >>> a[:,0]

    array([ 1, 4, 7, 10])
    >>> a[:,1]

    array([ 2, 5, 8, 11])
    >>> a[:,0] + a[:,1]

    array([ 3, 9, 15, 21])
    >>> a[:,0] + a[:, 1:]

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: operands could not be broadcast together with shapes (4) (4,2)


    To do this with a numpy array use fancy indexing:

    >>> a[:, [0, 2]]

    array([[ 1, 3],
    [ 4, 6],
    [ 7, 9],
    [10, 12]])

    So a solution could be:

    included = [0, 1, 2, 3, 5, 6, 7]
    oplot (t,d[:, included])


    Oscar
    Oscar Benjamin, Feb 7, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carl Gilbert

    Plotting points on a web page

    Carl Gilbert, Mar 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    535
    bruce barker
    Mar 7, 2005
  2. =?ISO-8859-1?Q?Per-Olav_Rus=E5s?=

    plotting API?

    =?ISO-8859-1?Q?Per-Olav_Rus=E5s?=, Jul 7, 2003, in forum: Java
    Replies:
    2
    Views:
    736
    Marco Schmidt
    Jul 7, 2003
  3. Thomas Nelson

    data plotting

    Thomas Nelson, May 15, 2005, in forum: Java
    Replies:
    2
    Views:
    355
    Thomas Weidenfeller
    May 17, 2005
  4. morc
    Replies:
    2
    Views:
    686
    IchBin
    Feb 23, 2006
  5. Steven D'Aprano

    Re: Plotting syntax

    Steven D'Aprano, Feb 7, 2013, in forum: Python
    Replies:
    0
    Views:
    138
    Steven D'Aprano
    Feb 7, 2013
Loading...

Share This Page