~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to scipy/io/examples/read_array_demo1.py

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#=========================================================================
 
2
# NAME: read_array_demo1
 
3
#
 
4
# DESCRIPTION: Examples to read 2 columns from a multicolumn ascii text 
 
5
# file, skipping the first line of header. First example reads into 
 
6
# 2 separate arrays. Second example reads into a single array. Data are
 
7
# then plotted.
 
8
#
 
9
# Here is the format of the file test.txt:
 
10
# --------
 
11
# Some header to skip
 
12
# 1 2 3
 
13
# 2 4 6
 
14
# 3 6 9
 
15
# 4 8 12
 
16
#
 
17
# USAGE:
 
18
# python read_array_demo1.py
 
19
#       
 
20
# PARAMETERS:
 
21
#
 
22
# DEPENDENCIES:
 
23
# matplotlib (pylab)
 
24
# test.txt
 
25
#
 
26
#
 
27
# AUTHOR: Simon J. Hook
 
28
# DATE  : 09/23/2005
 
29
#
 
30
# MODIFICATION HISTORY:
 
31
#
 
32
# COMMENT:
 
33
#
 
34
#============================================================================
 
35
 
 
36
from scipy import *
 
37
from scipy.io import read_array
 
38
from pylab import *
 
39
 
 
40
def main():
 
41
 
 
42
    # First example, read first and second column from ascii file. Skip first
 
43
    # line of header.
 
44
    # Note use of (1,-1) in lines to skip first line and then read to end of file
 
45
    # Note use of (0,) in columns to pick first column, since its a tuple need trailing comma
 
46
    x=read_array("test.txt",lines=(1,-1), columns=(0,))
 
47
    y=read_array("test.txt",lines=(1,-1), columns=(1,))
 
48
 
 
49
    #Second example, read the file into a single arry
 
50
    z=read_array("test.txt",lines=(1,-1), columns=(0,2))
 
51
    
 
52
    # Plot the data
 
53
    plot(x,y,'r--',z[:,0],z[:,1])
 
54
    show()
 
55
 
 
56
# The one and only main function
 
57
if __name__ == "__main__":
 
58
    main()