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