Re: Plotting syntax

Discussion in 'Python' started by Steven D'Aprano, Feb 7, 2013.

  1. On Wed, 06 Feb 2013 10:37:07 -0500, Vladimir Ivkovic wrote:

    > 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])
    >
    > The question is: How do I specify within the above command, for columns
    > 6:8 to be plotted?


    You don't give us enough information to be sure:

    - you don't tell us what library oplot comes from;

    - you don't tell us what t is;

    - you don't tell us what d is;

    - and d[:,0:4] looks like it could be a SyntaxError or a typo.


    But assuming that what you tell us actually is correct, then obviously if
    oplot (t,d[:,0:4]) plots columns 1-4, then oplot (t,d[:,5:8]) will surely
    plot columns 6-8.


    Python counts starting from 0, not 1, and uses half-open intervals: when
    giving a range of indexes, like 0:4, Python interprets that as follows:

    item at index 0 (the first item)
    item at index 1 (the second item)
    item at index 2 (the third item)
    item at index 3 (the fourth item)

    with index 4 being excluded.

    So 5:8 will include the sixth through eighth items.

    This notation is called "slicing", and d[0:4] is called "a slice".

    The idea is that if you number the items starting from zero, and imagine
    the boundaries between items (shown as | vertical lines):

    |0|1|2|3|4|5|6|7|8|9|10|11 ...

    then always slice on the boundary to the left of the given number:

    slice [0:4] => |0|1|2|3|

    slice [5:8] => |5|6|7|

    The only tricky part is remembering to count from zero instead of one.


    --
    Steven
     
    Steven D'Aprano, 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:
    544
    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:
    752
    Marco Schmidt
    Jul 7, 2003
  3. Thomas Nelson

    data plotting

    Thomas Nelson, May 15, 2005, in forum: Java
    Replies:
    2
    Views:
    367
    Thomas Weidenfeller
    May 17, 2005
  4. morc
    Replies:
    2
    Views:
    708
    IchBin
    Feb 23, 2006
  5. Oscar Benjamin

    Re: Plotting syntax

    Oscar Benjamin, Feb 7, 2013, in forum: Python
    Replies:
    0
    Views:
    129
    Oscar Benjamin
    Feb 7, 2013
Loading...

Share This Page