Re: Plotting syntax
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 "", line 1, in 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Plotting syntax
- 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]) > The question is: How do I specify within the above command, for > columns 6:8 to be plotted? > Thanks for any help you may provide. > Cheers, > Vlad > The information in this e-mail is intended only for the person to > whom it is > addressed. If you believe this e-mail was sent to you in error and > the e-mail > contains patient information, please contact the Partners Compliance > HelpLine at > http://www.partners.org/complianceline . If the e-mail was sent to > you in error > but does not contain patient information, please contact the sender > and properly > dispose of the e-mail. > -- > http://mail.python.org/mailman/listinfo/python-list Hi, 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 JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Plotting syntax
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 -- http://mail.python.org/mailman/listinfo/python-list