Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38288 > unrolled thread
| Started by | "Vladimir Ivkovic" <vivkovic@nmr.mgh.harvard.edu> |
|---|---|
| First post | 2013-02-06 10:37 -0500 |
| Last post | 2013-02-07 01:56 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Plotting syntax "Vladimir Ivkovic" <vivkovic@nmr.mgh.harvard.edu> - 2013-02-06 10:37 -0500
Re: Plotting syntax Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-07 01:56 +0000
| From | "Vladimir Ivkovic" <vivkovic@nmr.mgh.harvard.edu> |
|---|---|
| Date | 2013-02-06 10:37 -0500 |
| Subject | Plotting syntax |
| Message-ID | <mailman.1417.1360165032.2939.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
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.
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-02-07 01:56 +0000 |
| Message-ID | <511309e8$0$21782$c3e8da3$76491128@news.astraweb.com> |
| In reply to | #38288 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web