1 \documentclass[12pt]{article} |
1 \documentclass[12pt]{article} |
2 %\title{Plotting Data} |
2 |
3 %\author{FOSSEE} |
3 |
|
4 \title{Plotting Points} |
|
5 \author{FOSSEE} |
|
6 \usepackage{listings} |
|
7 \lstset{language=Python, |
|
8 basicstyle=\ttfamily, |
|
9 commentstyle=\itshape\bfseries, |
|
10 showstringspaces=false, |
|
11 } |
|
12 \newcommand{\typ}[1]{\lstinline{#1}} |
|
13 \usepackage[english]{babel} |
|
14 \usepackage[latin1]{inputenc} |
|
15 \usepackage{times} |
|
16 \usepackage[T1]{fontenc} |
|
17 \usepackage{ae,aecompl} |
|
18 \usepackage{mathpazo,courier,euler} |
|
19 \usepackage[scaled=.95]{helvet} |
|
20 |
4 \begin{document} |
21 \begin{document} |
5 \date{} |
22 \date{} |
6 \vspace{-1in} |
23 \vspace{-1in} |
7 \begin{center} |
24 \begin{center} |
8 \LARGE{Plotting Data}\\ |
25 \LARGE{Plotting Points}\\ |
9 \large{FOSSEE} |
26 \large{FOSSEE} |
10 \end{center} |
27 \end{center} |
11 \section{Plotting from Data files} |
28 \section{Plotting from Data files} |
12 \begin{verbatim} |
29 \begin{verbatim} |
13 l = [] #Empty List |
30 l = [] #Empty List |
19 tsq = [] |
36 tsq = [] |
20 for time in t: #Iterating through lists |
37 for time in t: #Iterating through lists |
21 tsq.append(t*t) |
38 tsq.append(t*t) |
22 plot(l, tsq, '.') # Plotting points |
39 plot(l, tsq, '.') # Plotting points |
23 \end{verbatim} |
40 \end{verbatim} |
|
41 \section{Plotting Points with Lists} |
|
42 |
|
43 \begin{lstlisting} |
|
44 In [1]: x = [0, 1, 2, 3] |
|
45 In [2]: y = [7, 11, 15, 19] |
|
46 In [3]: plot(x, y) |
|
47 In [4]: clf() |
|
48 In [5]: plot(x, y, 'o') # Plotting Circles |
|
49 #Dots - '.', #Dashed lines - '--' #Lines - '-' |
|
50 \end{lstlisting} |
|
51 |
|
52 \section{Lists} |
|
53 |
|
54 Initializing |
|
55 \begin{lstlisting} |
|
56 In [10]: mtlist = [] # Empty List |
|
57 In [11]: lst = [ 1, 2, 3, 4, 5] |
|
58 \end{lstlisting} |
|
59 Slicing |
|
60 \begin{lstlisting} |
|
61 In [12]: lst[1:3] # A slice. |
|
62 Out[12]: [2, 3] |
|
63 |
|
64 In [13]: lst[1:-1] |
|
65 Out[13]: [2, 3, 4] |
|
66 \end{lstlisting} |
|
67 Appending to lists |
|
68 \begin{lstlisting} |
|
69 In [14]: a = [ 6, 7, 8, 9] |
|
70 In [15]: b = lst + a |
|
71 In [16]: b |
|
72 Out[16]: [1, 2, 3, 4, 5, 6, 7, 8, 9] |
|
73 |
|
74 In [17]: lst.append(6) |
|
75 In [18]: lst |
|
76 Out[18]: [ 1, 2, 3, 4, 5, 6] |
|
77 \end{lstlisting} |
|
78 |
|
79 Iterating over a List |
|
80 \begin{lstlisting} |
|
81 In [19]: for each in b: # Iterating over the list, element-wise |
|
82 ....: print b # Print each element |
|
83 ....: |
|
84 \end{lstlisting} |
|
85 |
|
86 Splitting Strings |
|
87 \begin{lstlisting} |
|
88 In [20]: line = '1.2000e-01 7.4252e-01' |
|
89 In [21]: point = line.split() # Splits the string at the space |
|
90 Out[21]: ['1.2000e-01', '7.4252e-01'] |
|
91 \end{lstlisting} |
|
92 |
|
93 Plotting from Files |
|
94 \begin{lstlisting} |
|
95 In [22]: L = [] |
|
96 In [23]: T = [] |
|
97 |
|
98 #Open a file & operate on each line |
|
99 In [24]: for line in open('pendulum.txt'): |
|
100 .... point = line.split() |
|
101 .... L.append(float(point[0])) |
|
102 .... T.append(float(point[1])) |
|
103 In [25]: TSq = [] |
|
104 In [26]: for t in T: |
|
105 ....: TSq.append(t*t) |
|
106 ....: |
|
107 ....: |
|
108 In [27]: plot(L, TSq, '.') |
|
109 \end{lstlisting} |
|
110 |
24 \end{document} |
111 \end{document} |
25 |
112 |